找不到java BufferedReader文件
这是我的代码片段:
static String filepath = "test.txt";
public static void main(String[] args) throws IOException {
try{
BufferedReader reader = new BufferedReader(new FileReader(filepath));
String l = reader.readLine();
System.out.println(l);
}catch (FileNotFoundException e){
System.out.println(e);
}
catch(IOException e){
System.out.println(e);
}
java.io.FileNotFoundException: test.txt (No such file or directory)
这是我得到的一个例外
我应该使用什么文件路径?我将文本文件放在bin
文件夹中
我在Ubuntu上运行Eclipse,这很重要
# 1 楼答案
将文件放在项目文件夹的根目录中。如果项目根目录为
FileReader
,则将文件放入其中# 2 楼答案
如果您正在运行eclipse,并且有一个java项目,那么只需将该文件放入该项目中,它就会工作