Getting file character count
Im trying to get the character count of a file which contains only my name "Brandon". The problem is that i am getting two different results for the character count. The first System.out.println() returns the correct count and the second a result of 11 characters. :confused: This makes no sense to me. Any help would be appreciated. Thanks.
Code:
public int getFileCharCount(String file) {
String lineOnebyOne = null;
String finalText = null;
int numberOfChar = 0;
try{
BufferedReader br = new BufferedReader(new FileReader(file));
while((lineOnebyOne = br.readLine()) != null){
finalText += lineOnebyOne;
System.out.println(lineOnebyOne.length());
System.out.println(finalText.length());
}
numberOfChar = finalText.length();
br.close();
}catch(IOException e){System.err.println(e + "getFileCharCount");}
return numberOfChar;
}