gpt4 book ai didi

java - 找不到资源可运行的jar

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:20 25 4
gpt4 key购买 nike

将项目提取为可运行的 jar 后,我无法加载资源文件。

它在 Eclipse 中工作,但导出后会抛出 FileNotFoundException

我尝试将 res 文件夹放在 .jar 文件旁边,但没有任何帮助。我尝试过 JarSplice 并使其与所有库一起运行,但它因资源文件而停止。目标文件位于源文件夹中。

我能做什么?

代码

    FileReader fr = null;
try {
fr = new FileReader(new File("res/" + fileName + ".obj"));
} catch (FileNotFoundException e) {
System.err.println("Couldn't load object file!");
e.printStackTrace();
}

编辑:通过在 7zip 中打开可运行的 .jar 文件,我可以看到整个/res 文件夹在导出过程中消失了,并且该目录中的文件现在直接位于 .jar 文件的根文件夹中。

最佳答案

根据您的代码,res 文件夹应直接放置在当前工作目录之外,该目录应该是您运行 Java 命令的目录。例如,请参阅 how to determine the current working directory from inside Java 上的此问题.

关于java - 找不到资源可运行的jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34643737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com