正在尝试读取错误中的文本文件:目录的文件不存在-LINUX



我只是在学习java,在我目前的课程中,我正在学习如何读取文本文件。我做了老师做的所有事情,但当我尝试运行它时,我得到了一个错误:目录的文件不存在。(错误:/home/jean/Documentos/Livros.txt(Arquivo ou diretório不存在(

我在用linux,我做错了什么?

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class LeArquivos {
public static void main(String[] args) {
File file = new File("/home/jean/Documentos/Livros.txt");
Scanner scan = null;
try {
scan = new Scanner(file);
while(scan.hasNextLine()) {
System.out.println(scan.hasNextLine());
}`enter code here`
}
catch(IOException e) {
System.out.println("ERROR: " + e.getMessage());
}
finally {
if(scan != null) {
scan.close();
}   
}
}
}

如何检查部分目录。

Step 1 Open command line (windows + R type CMD) enter.
Step 2 Type cd /
Step 3 Type cd /home/jean/Documentos --> enter --> If command error part is incorrect.
Step 4 Type ls --> Fine file Livros.txt

如果文件找到零件是正确的。

如果未找到文件,则零件不正确。

更新:

Try就是代码。

public static void main(String[] args) {
File file = new File("/home/jean/Documentos/Livros.txt");
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine()) != null) {
System.out.println(st);
}
br.close();
} catch (IOException e) {
System.out.println("ERROR: " + e.getMessage());
}
}

跳跃是有帮助的。

最新更新