View html from archive using WebView

2019-08-20 03:55发布

问题:

I have zip-compressed file, which contains a set of html pages. I need to load html-pages from it. I need to redefine the mechanism of resolve of links. It is possible using WebView javafx?

回答1:

If I understand well your question. I'm guessing that you need to open html files.

I extracted the next code from javafx 2 tutorial from Oracle

WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.load("http://mySite.com");

The load function takes a regular URL, so you can put a URL like

file:///C:/temp/test.html

and you will load an archive from your machine.

Hope it helps.



回答2:

Try using ZipFile and ZipEntry to retrieve your html documents from the .zip file as an InputStream:

ZipFile zipFile = new ZipFile("path to your .zip");
ZipEntry zipEntry = new ZipEntry("name of your html file");
InputStream is = zipFile.getInputStream(zipEntry); //InputStream to your file