我在尝试读取文件时一直收到相同的错误。该文件在目录中确实存在,我做错了什么?
package test;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class MenuSample{
public static void main(String[] args) {
File f = new File("C:/Users/Joe/Documents/workspace/ArtificialLifeFX/res/latest.txt");
Scanner scanner = null;
try {
scanner = new Scanner(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
scanner.useDelimiter("\r\n");
}
}
I get the following error:
java.io.FileNotFoundException: C:\Users\Joe\Documents\workspace\ArtificialLifeFX\res\latest.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at test.MenuSample.main(MenuSample.java:16)
Exception in thread "main" java.lang.NullPointerException
at test.MenuSample.main(MenuSample.java:21)
如果我太幼稚了,请原谅,我是Java的新手。我在Windows 7上运行Eclipse Luna。
notepad "C:/Users/Joe/Documents/workspace/ArtificialLifeFX/res/latest.txt"
。这样能打开你的文件吗? - Tom