File Reading in Java [closed]

1

I'm trying to read a file ( arquivo.txt ) that is in the same folder as my class, but I run the code an error appears that did not find the file. Could someone check what's wrong? Thanks in advance.

My arquivo.txt :

Industria;2;90000
Comercio;3;45000
Residencia;1;3000

My Java class:

package jogo;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Tabuleiro {

    private static Scanner scanner;

    public static void main(String[] args) {

        try {
            scanner = new Scanner(new FileReader("arquivo.txt"));
            scanner = scanner.useDelimiter(";");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        while (scanner.hasNext()) {
            String imovel = scanner.next();
            String posicao = scanner.next();
            String valor = scanner.next();
            System.out.println(imovel);
            System.out.println(posicao);
            System.out.println(valor);
        }

    }

}
    
asked by anonymous 06.06.2017 / 17:05

1 answer

0

Here is a basic and functional example, if you have any problems you can comment below. Do not forget to pass the correct path of the file.

try {
        BufferedReader br = new BufferedReader(new FileReader("/root/Documentos/teste.txt"));
        while (br.ready()) {
            String linha = br.readLine();
            System.out.println(linha);
        }
        br.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    
06.06.2017 / 17:17