Meu projeto é Interfaces e o arquivo leitura.txt está nesse caminho: IdeaProjects/Interfaces/leitura, então entendo que está na raiz correta.
O código é esse:
package com.company;
import java.io.*;
public class TestaEntrada {
public static void main(String[] args) throws IOException {
InputStream is = new FileInputStream("leitura.txt");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine(); //lê a primeira linha
while(s != null){
System.out.println(s);
s = br.readLine();
}
br.close();
}
}
O erro que retorna é esse:
/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=52085:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Users/brunasantos/IdeaProjects/Interfaces/out/production/Interfaces com.company.TestaEntrada
Exception in thread "main" java.io.FileNotFoundException: leitura.txt (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:196)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:139)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:94)
at com.company.TestaEntrada.main(TestaEntrada.java:8)
Process finished with exit code 1
O que estou fazendo de errado?