If I read a file the have empty spaces between paragraphs, how do I count the empty spaces and subtract them from the total line count?
public int countLinesInFile(File f){
int lines = 0;
try {
BufferedReader reader = new BufferedReader(new FileReader(f));
while (reader.readLine() != null){
lines++;
}
reader.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return lines;
}
To see if a line is blank :
And to respect the excellent advices of @JB Nizet :