title: Read an integer with DataInputStream in Java
body: <p>I have this Java code:</p>
  
  <pre><code>import java.io.DataInputStream;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  
  public class DemoApp {
  
      public static void main(String args[]) {
  
          try (DataInputStream dis = new DataInputStream(new FileInputStream("abc.txt"))) {
  
              int k = dis.readInt();
              System.out.println(k);
          }
  
          catch (FileNotFoundException fnfe) {
  
              System.out.printf("ERROR: %s", fnfe); 
          }
  
          catch (IOException ioe) {
  
              System.out.printf("ERROR: %s", ioe);
          }
      }
  
  }
  </code></pre>
  
  <p>When the abc.txt file contains the number 987 I have this ERROR: java.io.EOFException if the abc.txt contains the number 1234 when I run the program I have this result: 825373492. I just want to understand how exactly is working this readInt() method from DataInputStream and why I have this error for some numbers. Thank you!</p>