title: Check files exist in a directory
body: <p>I want to read files in a folder using Java. Unfortunately sometimes the files are missing and I get NPE.</p>
  
  <pre><code>public static HashMap&lt;String, Integer&gt; getCPUTemp() throws IOException
      {
          File directory = new File("/sys/devices/virtual/thermal");
  
          if (directory.exists())
          {
              HashMap&lt;String, Integer&gt; usageData = new HashMap&lt;&gt;();
  
              File[] fList = directory.listFiles();
  
              for (File file : fList)
              {
                  if (file.isDirectory() &amp;&amp; file.getName().startsWith("thermal_zone"))
                  {
                      ......................
                  }
              }
              return usageData;
          }
          return null;
  </code></pre>
  
  <p>How can I prevent this and return <code>null</code> if the files are not there? Can you show me a solution with Java 8?</p>