I want to read a series of numbers from a txt file, so I did this to test if it gave me the first value:
try {
Path p = Paths.get("DatosEA.txt");
File f = p.toFile();
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String data;
System.out.println("Revisión: " + br.readLine());
System.out.println("Revisión (no de línea): " + br.read());
br.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
If this is in the DatosEA.txt:
116
118
123
135
141
147
154
165
166
166
168
174
179
186
But this output gives me:
Revisión: null
Revisión (no de línea): -1
What could have gone wrong? It should be noted that all this is within a class that extends JPanel called Grafico and I call it with a JPanel that is the object of that class in my window. I put the code inside an @Override paint method of the Graphic class.
Update: I have put the code inside the main of the main class of a new project and it works perfectly. I'm still looking for the source of the error.