嗨,我有一个 Java 类,它在 Windows 中运行良好,但在 Mac OSX 雪豹中运行良好。我在两个操作系统上都使用 Eclipse。在 Mac OSX 上,它的 throwing file not found 异常。
基本上我正在尝试使用 BufferedReader 和 FileReader 读取文件,并将文件放在 \resources\
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class ReadFileContents {
/**
* @param args
*/
public static void main(String[] args) {
BufferedReader br = null;
String line = "";
try {
br = new BufferedReader(new FileReader("resources\\abc"));
while((line = br.readLine())!= null)
{
System.out.println("Read ::: "+line+" From File.");
}
} catch (FileNotFoundException fne) {
fne.printStackTrace();
}catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
在 Mac 上它给
java.io.FileNotFoundException: resources\abc (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:41)
at ReadFileContents.main(ReadFileContents.java:18)
我是否需要在我的 Eclipse 中进行任何特殊配置才能使其正常工作...