Boas pessoal,
Estou a ter um erro claro que não é encontrado o ficheiro que estou a tentar ler. O meu ficheiro leitura.txt está criado na pasta raiz do projecto "src". E estou a tentar ir ler com o seguinte código:
package ao.co.sistetulene.programa;
import java.io.*;
public class TestaJavaIO {
public static void main(String[] args) throws IOException {
//Abrir arquiva para leitura atribuindo a variável do tipo InputStream: "is"
InputStream is = new FileInputStream("leitura.txt");
//Tranformar byte da variável is, em caracter utilizando o encoding padrão do JAVA
InputStreamReader isr = new InputStreamReader(is);
//Ler varias linha do texto de uma vez só, utilizando buffer:
BufferedReader br = new BufferedReader(isr);
}
}
Ao compilar este código é devolvido a seguinte Exception:
Exception in thread "main" java.io.FileNotFoundException: leitura.txt (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at ao.co.sistetulene.programa.TestaJavaIO.main(TestaJavaIO.java:12)
Process finished with exit code 1
Eu estou a utilizar o IntelliJ IDEA 2017.2.3. Em que por cima da Exception tem o seguintes dizer:
"C:\Program Files\Java\jdk1.8.0_131\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2\lib\idea_rt.jar=60568:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_131\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar;C:\Meus Treinamentos\Java\Alura\Java II\banco\out\production\banco" ao.co.sistetulene.programa.TestaJavaIO