ran*_*ech 1 java text-files 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);
}
Run Code Online (Sandbox Code Playgroud)
但出于某种原因,我得到了一个
java.io.FileNotFoundException
我将words.txt文件放在与所有.java文件相同的文件夹中
我究竟做错了什么?谢谢!
提示:将此行添加到您的代码中...
System.out.println(file.getAbsolutePath());
Run Code Online (Sandbox Code Playgroud)
然后将该路径与文件实际位置进行比较.问题应该立即显而易见.
| 归档时间: |
|
| 查看次数: |
2999 次 |
| 最近记录: |