title: How to see if resource file exists in Java?
body: <p>I am trying to output text to a resource file in Java like so:</p>
  
  <pre><code>File file = new File(MLM.class.getClassLoader().getResource("mazes.txt").toString());
  BufferedWriter out = new BufferedWriter(new FileWriter(file));
  ..
  </code></pre>
  
  <p>but because the resource file has not been created I get a null pointer exception. How can I create a blank resource file first if it doesn't exist already to avoid this error?</p>