netbeans、cmd 和 .bat 或 .cmd 中的路径差异
我面临一个奇怪的问题。我的代码从 Netbeans 或 cmd 运行得很好
java -jar MP2.jar
,但是当我尝试从 .bat 或 .cmd 运行它时,
"%JAVA_HOME%"\bin\java -jar .. \dist\MP2.jar > test_mp2_out.txt
我的文本文件中出现错误
DataIn\nrmavg.txt (The System cannot find the path specified)
有 new FileReader(nrmavg.txt) 的行出现空指针异常
,或者在我 如果需要的话可以提供更多代码,但我认为这可能是一个Windows问题。 有什么想法吗?
I am facing a strange issue. My code runs just fine from Netbeans or cmd with
java -jar MP2.jar
but when I try to run it from the .bat or .cmd
"%JAVA_HOME%"\bin\java -jar .. \dist\MP2.jar > test_mp2_out.txt
I get an error in my text file
DataIn\nrmavg.txt (The System cannot find the path specified)
or a null pointer exception at the line I have new FileReader(nrmavg.txt)
I can provide more code if needed, but I think this may be a windows problem.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 FileReader("nrmavg.txt") 不会在 .jar 中查找文件,而只是在当前目录中查找。你能尝试用这样的东西代替吗?
I think FileReader("nrmavg.txt") won't be looking for a file inside .jar, just a current directory. Could you try using something like this instead?
Netbeans 是否在您的 dist 目录中创建了一个名为 lib 的目录?如果是的话,可能是Java无法访问的。您能否在 cmd 文件中尝试以下操作:
其中 PROJECT_FOLDER 是 Netbeans 项目文件夹。
Is Netbeans creating a directory called lib on your dist directory? If yes, maybe it is unreacheable for Java. Could you try the following in your cmd file:
Where PROJECT_FOLDER is the Netbeans project folder.