gpt4 book ai didi

java - 找不到 .txt 文件?

转载 作者:行者123 更新时间:2023-12-01 12:36:43 25 4
gpt4 key购买 nike

我找不到要读取的 .txt 文件。

这是代码:

public void read(){

try {
File file = new File("las");
String path = file.getAbsolutePath();
System.out.println(path);
BufferedReader reader = new BufferedReader(new FileReader("/Users/Asus/workspace/testhitodit/las.txt"));
String line = reader.readLine();
while(line != null) {
System.out.println(line);
line = reader.readLine();
}
reader.close();
}catch(FileNotFoundException e) {
System.out.println("File not found");
}catch(IOException e) {
System.out.println("SOmething went wrong");
}
}

这是打印出来的内容:

C:\Users\Asus\workspace\testhitodit\las

找不到文件

该文件夹中有一个名为 las.txt 的文件。

为什么不起作用?

最佳答案

   //include the file extension
File file = new File("las.txt");
String path = file.getAbsolutePath();
System.out.println(path);

//pass the file you created to your file reader
BufferedReader reader = new BufferedReader(new FileReader(file));

关于java - 找不到 .txt 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25516503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com