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

问题描述 投票:0回答:1

我只是学习Java,而在我目前的课程中,我正在学习如何读取文本文件。我做了老师所做的一切,但是当我尝试运行它时,我得到一个错误:目录文件不存在。 (错误:/home/jean/Documentos/Livros.txt(不存在的档案))

我正在使用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();
            }   
    }
    }
}

java file
1个回答
0
投票

如何检查目录的一部分。

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

如果找到的文件部分正确。

如果找不到文件部分不正确。

Hop是帮助。

© www.soinside.com 2019 - 2024. All rights reserved.