1

我想将 html 文件添加到 jar 文件并通过 windows 应用程序项目中的 jar 访问它们我如何访问它们我使用以下代码。

   try{
      File f1= new File(getClass.getResource("/path is the src folder/));
     }

但它显示没有找到合适的构造函数

4

1 回答 1

3

File不会URL作为参考。像这样的嵌入式资源实际上不是文件,它们是InputStream资源的 s。

根据您向他们展示的方式,将决定您需要做什么。

例如,通过它的方法JEditorPane获取一个URLsetPage

更新

您应该能够使用类似的东西将页面直接加载到编辑器窗格中......

// editor pane is a reference to a JEditorPane
editorPane.setPage(getClass.getResource("/path is the src folder/"));
于 2012-11-28T04:30:19.980 回答