从 Eclipse 文件夹加载 Java HTML 文件

发布于 2025-01-08 06:23:40 字数 1111 浏览 0 评论 0原文

我在编辑器窗格中加载 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:

enter image description here

Can anybody help please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2025-01-15 06:23:40

这看起来像是文件 URL 中的相对路径。您需要使用绝对路径。对于与应用程序捆绑的资源,您可以获得如下 URL:

final String resourcePath = "foobar.html";
URL resourceURL = Thread.currentThread().getContextClassLoader().getResource(resourcePath);
JEditorPane editorPane = new JEditorPane(resourceURL);

假设您的类路径根目录中有一个名为“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:

final String resourcePath = "foobar.html";
URL resourceURL = Thread.currentThread().getContextClassLoader().getResource(resourcePath);
JEditorPane editorPane = new JEditorPane(resourceURL);

This assumes that there is an HTML file named 'foobar.html' at the root of your classpath. Extend the pseudocode to serve your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文