View html from archive using WebView

2019-08-20 03:58发布

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?

2条回答
够拽才男人
2楼-- · 2019-08-20 04:21

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.

查看更多
成全新的幸福
3楼-- · 2019-08-20 04:32

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
查看更多
登录 后发表回答