title: How to read a file created at runtime?
body: <p>Using Java 8.</p>
  
  <p>Basically, in a unit test (junit) I have this code:</p>
  
  <pre><code>callSomeCode();
  assertTrue(new File(this.getClass().getResource("/img/dest/someImage.gif").getFile()).exists());
  </code></pre>
  
  <p>In <code>callSomeCode()</code>, I have this:</p>
  
  <pre><code>InputStream is = bodyPart.getInputStream();
  File f = new File("src/test/resources/img/dest/" + bodyPart.getFileName()); //filename being someImage.gif
  FileOutputStream fos = new FileOutputStream(f);
  byte[] buf = new byte[40096];
  int bytesRead;
  while ((bytesRead = is.read(buf)) != -1)
     fos.write(buf, 0, bytesRead);
  fos.close(); 
  </code></pre>
  
  <p>The first time the test runs, <code>this.getClass().getResource("/img/dest/someImage.gif")</code>returns <code>null</code> although the file is well created.</p>
  
  <p><strong>The second time (when the file was already created during the first test run then just overwritten), it is non-null and the test passes.</strong>  </p>
  
  <p>How to make it work the first time?<br>
  Should I configure a special setup in IntelliJ to automatically refresh the  folder where the file is created?  </p>
  
  <p>Note that I have this basic maven structure: </p>
  
  <pre><code>--src
  ----test
  ------resources   
  </code></pre>