title: Java check if file is empty: IOException: null
body: <p>I'm trying to load a file to my ArrayList, program creates a file if it doesn't exist. I'm getting IOException: Null as at the beginning file is empty. How I can avoid that error and check if file is empty or not? Here's my code:</p>
  
  <pre><code>     File f = new File(fileName);
  
       try {
          if( !f.exists() ){
              f.createNewFile();
          }
  
          inputStream = new ObjectInputStream(new FileInputStream(f));
          scores = (ArrayList&lt;Score&gt;) inputStream.readObject();
       } catch (IOException e) {
          System.out.println("IO Error: " + e.getMessage());
       } finally {
           ...
       }
  </code></pre>