I've checked this SO question but still can't find a solution.
I'm trying to view an offline HTML file. The file can be stored at either Storage or FileSystemStorage. However, I'm not sure how to obtain a URL for files in Storage so I used FileSystemStorage.getAppHomePath. The code that I'm using is as shown:
BrowserComponent bc = new BrowserComponent();
String appPath = fs.getAppHomePath();
bc.setURL(appPath + "1.html");
where the HTML (and the support files not shown) was downloaded from web using:
Util.downloadUrlToFile("https://google.com", appPath + "1.html", false);
The .cn1/ folder does contain 1.html, but the page was not loaded. The error code is
Received exception: File not found
java.lang.Throwable: File not found
at javafx.scene.web.WebEngine$LoadWorker.describeError(WebEngine.java:1463)
at javafx.scene.web.WebEngine$LoadWorker.dispatchLoadEvent(WebEngine.java:1402)
at javafx.scene.web.WebEngine$LoadWorker.access$1200(WebEngine.java:1280)
at javafx.scene.web.WebEngine$PageLoadListener.dispatchLoadEvent(WebEngine.java:1267)
at com.sun.webkit.WebPage.fireLoadEvent(WebPage.java:2499)
at com.sun.webkit.WebPage.fwkFireLoadEvent(WebPage.java:2343)
at com.sun.webkit.network.URLLoader.twkDidFail(Native Method)
at com.sun.webkit.network.URLLoader.notifyDidFail(URLLoader.java:883)
at com.sun.webkit.network.URLLoader.lambda$didFail$104(URLLoader.java:866)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748)
Another approach, with
String html = Util.readToString(fs.openInputStream(appPath + "1.html"));
bc.setPage(html, appPath);
can show the html but does not load the supporting file, which is a .js file. Copying the .js content into the html in a <script> tag allows everything to show correctly.
I'd like to ask if this behavior is due to any bug in my code, and how do I solve this problem?

CodenameOneImplementation#setBrowserURLcontains this line, which looks a bit suspicious: InputStream i = Display.getInstance().getResourceAsStream(getClass(), url.substring(6)); The simulator probably use another implementation tho, as adding a breakpoint there doesn't affect the simulator - R. Wang