【发布时间】:2012-09-05 07:46:34
【问题描述】:
请注意,我说的是 Java 7,因为自 Java 6 以来,Java .app 包的 info.plist 规范似乎发生了一些变化。
目前我的代码如下所示:
File file = new File( "documentation/index.html" );
if (file.exists()) {
// opens the URI in the browser
GUIUtils.openURI( file.toURI() );
} else {
// opens the URI in the browser
GUIUtils.openURI( getClass().getResource( "/documentation/index.html" ).toURI() );
}
在应用程序包的Java 子文件夹中,我有一个“文档”子文件夹。我尝试了很多方法,但无济于事:
- 在 info.plist 中,将工作目录设置为 Java 文件夹(带有
-Duser.dirJVMArgument 属性) - 文件看似具有正确的路径,但file.exists()返回 false。 - 尝试将 ClassPath 设置为 Java 文件夹。 (
getClass().getResource()仍然返回 null)
【问题讨论】:
-
我想我会将文件解压缩到一个临时文件夹并从那里打开它。
标签: java macos java-7 resource-files app-bundle