试图在java中读取文本文件-错误:目录文件不存在-LINUX

试图在java中读取文本文件-错误:目录文件不存在-LINUX,java,file,Java,File,我正在学习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

我正在学习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());
    }

}

Hop是帮助。

如何检查部分目录

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());
    }

}

Hop是帮助。

ls-a/home/jean/Documentos的结果是什么?零件文件不存在或零件文件错误。“ls-a/home/jean/Documentos”的结果是什么?零件文件不存在或零件文件错误。嘿,伙计,我可以找到问题。我没有保存包含扩展名的文件。在我像Livros.txt一样保存之后,它就工作了。但是,现在我又遇到了另一个问题。我的程序刚刚运行,但它在一个无限的真循环中输出。它应该列出Livros.txt内容。这有什么问题?您期望的结果是什么。刚刚将输出行中的scan.hasNextLine()更改为scan.NextLine(),它就工作了。太多了。嘿,老兄,我能找到问题。我没有保存包含扩展名的文件。在我像Livros.txt一样保存之后,它就工作了。但是,现在我又遇到了另一个问题。我的程序刚刚运行,但它在一个无限的真循环中输出。它应该列出Livros.txt内容。这有什么问题?您期望的结果是什么。刚刚将输出行中的scan.hasNextLine()更改为scan.NextLine(),它就工作了。很多。