![](/img/trans.png)
[英]FileNotFoundException cannot be resolved to a type when trying to read a .txt file in java
[英]FileNotFoundException when I try to read txt file via Command Line
我在eclipse中构建了一个使用txt文件的项目。 该文件位于主文件夹项目中。
我通过命令行获取文件名作为参数,我得到FileNotFoundException
。 我尝试使用Scanner
Object并从eclipse获取文件名作为输入..它的工作原理。 (我只插入文件名:file.txt。而不是完整路径)所以为什么通过eclipse它的工作和命令行不?
谢谢! 这是例外:
java.io.FileNotFoundException: bigMaze.txt (The system cannot find the file spec
ified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileReader.<init>(FileReader.java:72)
at BFS.BFS.readFile(BFS.java:43)
at BFS.BFS.InsertMaze(BFS.java:57)
at BFS.BFS.StartMain(BFS.java:16)
at search.main(search.java:20)
Exception in thread "main" java.lang.NullPointerException
at BFS.BFS.InsertMaze(BFS.java:62)
at BFS.BFS.StartMain(BFS.java:16)
at search.main(search.java:20)
如果从命令行运行,请尝试将该文件放在与.class文件相同的目录中
ProjectRoot
bin
file.txt
program.class
src
如果程序是从eclispe运行的,那么该文件应该放在原来的位置。 直接在项目根目录下。
这都是考虑使用String filename = "file.txt";
运行程序String filename = "file.txt";
我认为问题是关于你的txt文件的路径名。 在命令提示符的情况下,您必须提供完整的路径,如:“MyComputer://D/yourFile.txt”,但使用eclipse,您只能提供“D://yourFile.txt”。 它会工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.