title: Reading a text file with a Scanner in Java - Token's return character
body: <p>I'm triying to read the text file below with a <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html" rel="nofollow">java.util.Scanner</a> in a simple Java Program.</p>
  
  <pre><code>0001;GUAJARA-MIRIM;RO
  0002;ALTO ALEGRE DOS PARECIS;RO
  0003;PORTO VELHO;RO
  </code></pre>
  
  <p>I read the text file using the code below:</p>
  
  <pre><code>scanner = new Scanner(filerader).useDelimiter("\\;|\\n");
  while (scanner.hasNext()) {
      int id= scanner.nextInt();
      String name = scanner.next();
      String code = scanner.next();
  
      System.out.printf(".%s.%s.%d.\n", name, code, id);
  }
  </code></pre>
  
  <p>The results are:</p>
  
  <pre><code>.GUAJARA-MIRIM.RO.1
  .
  .ALTO ALEGRE DOS PARECIS.RO.2
  .
  .PORTO VELHO.RO.3
  .
  </code></pre>
  
  <p>But the result of the third token of each line has an incovenient '\r' caracther at the end (ANSI code 13). I have no idea why (I used the '.' character on the formatting string to to make it clear where the '\r' is).</p>
  
  <p>So,</p>
  
  <ol>
  <li>Why there's a '\r' at the end of the third token?</li>
  <li>How to bypass it.</li>
  </ol>
  
  <p>It is very simple to use an workaround like <code>code.substring(0, 2)</code>, but instead I want to understand why there's a '\r' character there.</p>