title: Checking if the input has finished
body: <p>So I'm a Java-newbie and started some playing with files. Say I have some file "tes.t" containing data of a type known for me - assume they're int-double-int-double and so forth. I don't know the amount of such pairs inside, though - how can I make sure the input has finished? For my current knowledge, I thought of something like this:</p>
  
  <pre><code>try{
          DataInputStream reading = new DataInputStream(new FileInputStream("tes.t"));
          while(true)
          {
              System.out.println(reading.readInt());
              System.out.println(reading.readDouble());
          }
          }catch(IOException xxx){}
  }
  </code></pre>
  
  <p>However, this infinite loop here makes me somehow uncomfortable. I mean - I guess the IOException should catch on as soon as the input has finished but I'm not sure if that's a good way to go. Is there any better way to do this? Or rather - <em>what</em> is a better approach as I'm sure mine is bad :)</p>