如何在jwebbrowser中加载相对于当前java文件的本地文件? [英] how to load the local files relative to the current java file in jwebbrowser?
问题描述
如何在JWebbrowser中加载相对于当前java文件的本地文件?我知道我可以用
navigate( path加载我的页面);
问题是如何设置相对路径!
例如我的java代码是:
D:\ Eclipse_Project \ MyProject \ src \ javaCode \browser.java
和html文件位于:
D:\ Eclipse_Project \ MyProject \ src; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ java> webBrowser.navigate( file:/// D:/ Eclipse_Project / MyProject / src / pages / html .html);
我也尝试使用代码但是没有加载!
String webContent = new Scanner(new file(src\\pages\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
webBrowser.setHTMLContent(webContent);
注意:我的html文件还包含CSS javaScript。
- 在顶级项目文件夹中创建/资源
- 添加到类路径
- 确保在导出中检查资源还有
- 玩得开心
你可以在任何地方添加数据,但组成一个文件夹res/是常识资源/资源(在您的情况下甚至可能是网络)在顶层。
how would I load local files relative to the current java file in JWebbrowser? I know that I could load my page with
navigate("path");
the problem is how to set relative path!
for example my java code is in :
D:\Eclipse_Project\MyProject\src\javaCode\browser.java
and the html file is in :
D:\Eclipse_Project\MyProject\src\pages\html.html
but I don't want to use as follow:
webBrowser.navigate("file:///D:/Eclipse_Project/MyProject/src/pages/html.html");
also I try following code but it didn't load!
String webContent = new Scanner(new File("src\\pages\\html.html")).useDelimiter("\\Z").next(); webBrowser.setHTMLContent(webContent);
note: my html file also contains CSS an javaScript.
- create /resources in top level project folder
- add to classpath
- make sure resources are checked in the export also
- have fun
You can add data at any place, but it's common sense to make up a folder "res" / "resource" / "resources" (might even be "web" in your case) in the top level.
这篇关于如何在jwebbrowser中加载相对于当前java文件的本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!