2016-09-26 91 views
1

我在我的應用程序中有WebView控件。如何將本地存儲的頁面加載到WebView控件?

private WebView webview = new WebView(); 

我使用這樣的

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

和它工作得很好,但我怎麼用它來加載本地存儲的頁面。 例如:

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

傳遞給WebEngine你試過'「文件: /// yourfile.html「' – OscarRyz

+0

是的。此外,我使用類似的路徑來加載圖像:新ImageView(新圖像(「file:red_arrow.png」)); – hal

回答

3

可以創建一個URLFilePath

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