I am writing a method to count the number of lines in a text document in Java.
public int numeroLineas(FileReader re) throws IOException {
String str;
BufferedReader br = new BufferedReader(re);
Vector<String> v = new Vector<String>();
while ((str = br.readLine()) != null) {
v.add(str);
}
if (v != null) {
br.close();
}
System.out.println("Lineas: " + v.size());
return v.size();
}
The While
cycle can not be accessed because br.ReadLine () returns null
.
The result in the console is always:
Lineas: 0
0