下面的代码段会导致此错误:
Run Code Online (Sandbox Code Playgroud)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"));
Run Code Online (Sandbox Code Playgroud)
该路径有效,因为我可以看到使用此代码列出的文件:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我在Java中回顾了许多关于OS/X路径的文章,但没有解决我的问题.我将在Windows PC上尝试它,看看问题是否特定于OS/X和/或我的Eclipse安装.