打開文件中的Java下面的代碼片段會導致這個錯誤:在OS/X
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type FileNotFoundException
String path = "/Users/jfaig/Documents/workspace/my_array/";
BufferedReader in = new BufferedReader(new FileReader(path + "Matrix.txt"));
的路徑是有效的,因爲我可以看到這個代碼列出的文件:
File dir = new File(path);
String[] chld = dir.list();
if(chld == null){
System.out.println("Specified directory does not exist or is not a directory.");
System.exit(0);
} else {
for(int i = 0; i < chld.length; i++){
String fileName = chld[i];
System.out.println(fileName);
}
}
我回顧了許多關於Java中OS/X路徑的文章,但沒有解決我的問題。我將在Windows PC上嘗試它,看看問題是否特定於OS/X和/或我的Eclipse安裝。