title: read digits (instead of int) from a txt file in java
body: <p>I have a file like this </p>
  
  <p>test.txt:</p>
  
  <p>122352352246</p>
  
  <p>12413514316134</p>
  
  <p>Now I want to read each digit a time, and store it as one element in, say, a list.
  I tried using Scanner. But it will read a line each time, and outputs a long integer. That means if I want to get the digits, I need to further separate the digits in that integer. I guess there must be an elegant way to directly read one digit each time. Below is my code</p>
  
  <pre><code>public class readDigits {
  
  public static void main(String[] args) throws IOException{
      List&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
      File file = new File("test.txt");
      Scanner in = new Scanner(file);
      int c;
      try {
           while (in.hasNext()){
               c = in.nextInt();
               list.add(c);
  
          }
  
      }
      finally {
          System.out.println(list);
          in.close();
      }
  
  }
  
  
  }
  </code></pre>