Java FileReader的问题 [英] Problem with Java FileReader
本文介绍了Java FileReader的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我的代码中有这个
File file = new File("words.txt");
Scanner scanFile = new Scanner(new FileReader(file));
ArrayList<String> words = new ArrayList<String>();
String theWord;
while (scanFile.hasNext()){
theWord = scanFile.next();
words.add(theWord);
}
但出于某种原因,我得到的是
But for some reason I am getting a
java.io.FileNotFoundException
java.io.FileNotFoundException
我有words.txt文件与我的所有.java文件相同的文件夹
I have the words.txt file in the same folder as all of my .java files
我做错了什么?谢谢!
推荐答案
提示:将此行添加到您的代码中...
Tip: add this line to your code...
System.out.println(file.getAbsolutePath());
然后将该路径与文件实际位置进行比较。问题应该立即显而易见。
Then compare that path with where your file actually is. The problem should be immediately obvious.
这篇关于Java FileReader的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文