【发布时间】:2014-02-19 13:48:46
【问题描述】:
好吧,这很奇怪和荒谬..
我有这个非常简单的代码:
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new FileReader("input.txt"));
String s;
while ((s = br.readLine()) != null) {
System.out.println(s);
}
}
我还尝试将 BufferedReader... 包装在 try-catch 块中。为什么会抛出这个错误:
Exception in thread "main" java.io.FileNotFoundException: /input.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at java.io.FileReader.<init>(FileReader.java:58)
它被扔到BufferedReader 行。
该文件与 java 文件位于同一包/目录中。我尝试过声明 throws Exception 和 try-catch 块。
无论我做什么,我都会不断收到此错误。
【问题讨论】:
-
The file is in the same package / directory as the java file.。你的期望是错误的。
标签: java file-io io bufferedreader