Conflicting character counts
<p>I'm trying to find the number of characters in a given text file.</p>

<p>I've tried using both a scanner and a BufferedReader, but I get conflicting results. With the use of a scanner I concatenate every line after I append a new line character. E.g. like this:</p>

<pre><code>    FileReader reader = new FileReader("sampleFile.txt");
    Scanner lineScanner = new Scanner(reader);
    String totalLines = "";

    while (lineScanner.hasNextLine()){
        String line = lineScanner.nextLine()+'\n';
        totalLines += line;
    }
    System.out.println("Count "+totalLines.length());
</code></pre>

<p>This returns the true character count for my file, which is 5799</p>

<p>Whereas when I use:</p>

<pre><code> BufferedReader reader = new BufferedReader(new FileReader("sample.txt"));

 int i;
 int count = 0;
 while ((i = in.read()) != -1) {
    count++;
 }

 System.out.println("Count "+count);
</code></pre>

<p>I get 5892.</p>

<p>I know using the lineScanner will be off by one if there is only one line, but for my text file I get the correct ouput.</p>

<p>Also in notepad++ the  file length in bytes is 5892 but the character count without blanks is 5706. </p>
