hal hal - 2 months ago 9
Java Question

How to load locally stored page to WebView controll?

I have WebView control in my application.

private WebView webview = new WebView();


i use it like this

webview.getEngine().load("http://google.com/");


and it works well, but how do i use it to load locally stored page.
For example:

webview.getEngine().load("file:myLocallyStoredPage.html");

Answer

You can create the a URL to pass to the WebEngine from a File or Path

File file = ...
URL url = file.toURI().toURL();
Path path = ...
URL url = path.toUri().toURL();
webview.getEngine().load(url.toExternalForm());