Scanner delimiter not working as expectedwith input file (Java)
<p>I am writing a program to read input from a text file that will always follow the format of char:int, such as the following:</p>

<pre><code>A:3
B:1
C:2
D:2
</code></pre>

<p>(eof here)</p>

<p>I want to read in the characters and their corresponding numbers, ignoring the colons.</p>

<p>In my program I have the following declarations and initializations:</p>

<pre><code>String fileName = "input.txt";
File file = new File(fileName);
Scanner in = new Scanner(file).useDelimiter(":");
</code></pre>

<p>Then, I try to read from my file using the following loop:</p>

<pre><code>while(in.hasNextLine()){
        String t = in.next();
        int n = in.nextInt();
        ....
}
</code></pre>

<p>When I attempt to run my program in Eclipse, I receive the following error(s):</p>

<blockquote>
  <p>Exception in thread "main" java.util.InputMismatchException
      at java.util.Scanner.throwFor(Scanner.java:864)
      at java.util.Scanner.next(Scanner.java:1485)
      at java.util.Scanner.nextInt(Scanner.java:2117)
      at java.util.Scanner.nextInt(Scanner.java:2076)
      at Huffman_Encoder.main(Huffman_Encoder.java:26)</p>
</blockquote>

<p>i.e., the line: <code>int n = in.nextInt();</code> is throwing an exception. I am not sure why this is the case. From my understanding of Scanner delimiters, I should be skipping over the colons and so <code>int n = in.nextInt();</code> should put the value following the colon into <code>n</code>.</p>

<p>What am I not seeing here?</p>

<p>OS is Windows 10, if that matters. Thank you.</p>

<p><strong>edit:</strong> upon further testing, I've pinpointed the error as occurring immediately after <code>String t = in.next();</code>
Printing out <code>t</code> immediately after this shows 'A', and then the program throws its exception at <code>int n = in.nextInt();</code></p>