【发布时间】:2012-05-17 21:11:02
【问题描述】:
我正在尝试在 java 中读取文件:
Public class Test{
public static void main (String [] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("test.in"));
//...
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.out")));
//...
}
}
1) “test.in”的位置应该在哪里? (src?bin????)
2) "test.out" 将位于何处?
【问题讨论】:
-
你是如何执行你的代码的?从命令行还是从 eclipse 之类的地方?
-
从您询问 src 和 bin 的事实来看,我假设您正在使用某种 SDK?否则答案是微不足道的;该位置将与您执行 java 文件的位置相同。提供有关您正在使用的 SDK 的更多信息,有人可以更好地回答。
-
"Java 在哪里寻找文件?"为什么不问 Java 本身:
System.out.println(System.getProperty("user.dir"));编辑:1+ 到 @mebigfatguy,因为我现在看到他在我面前给出了同样的建议。