从 Eclipse 文件夹加载 Java HTML 文件
我在编辑器窗格中加载 HTML 文件并显示它时遇到问题。我正在使用的代码是:
window_pane = new JEditorPane("file:///assets/www/index.html");
但这只是给出了一些错误:
Exception in thread "main" java.io.FileNotFoundException: \assets\www\index.html (Het systeem kan het opgegeven pad niet vinden)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at javax.swing.JEditorPane.getStream(Unknown Source)
at javax.swing.JEditorPane.setPage(Unknown Source)
at javax.swing.JEditorPane.setPage(Unknown Source)
at javax.swing.JEditorPane.<init>(Unknown Source)
at nl.xedus.battlex.java.WebBrowser.<init>(WebBrowser.java:33)
at nl.xedus.battlex.java.WebBrowser.main(WebBrowser.java:72)
ScreenShot:
有人可以帮忙吗?
I am encountering a problem loading an HTML file in an editor pane and displaying it. The code I am using is:
window_pane = new JEditorPane("file:///assets/www/index.html");
But that just gave some errors:
Exception in thread "main" java.io.FileNotFoundException: \assets\www\index.html (Het systeem kan het opgegeven pad niet vinden)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at javax.swing.JEditorPane.getStream(Unknown Source)
at javax.swing.JEditorPane.setPage(Unknown Source)
at javax.swing.JEditorPane.setPage(Unknown Source)
at javax.swing.JEditorPane.<init>(Unknown Source)
at nl.xedus.battlex.java.WebBrowser.<init>(WebBrowser.java:33)
at nl.xedus.battlex.java.WebBrowser.main(WebBrowser.java:72)
ScreenShot:
Can anybody help please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像是文件 URL 中的相对路径。您需要使用绝对路径。对于与应用程序捆绑的资源,您可以获得如下 URL:
假设您的类路径根目录中有一个名为“foobar.html”的 HTML 文件。扩展伪代码以满足您的需求。
That looks like a relative path in your file URL. You need to use an absolute path. For resources bundled with your application you can get a URL like this:
This assumes that there is an HTML file named 'foobar.html' at the root of your classpath. Extend the pseudocode to serve your needs.