title: Java program can't use file write after it's written
body: <p>The thing is this, I am creating a file, that an XML resource uses, right after creation. When the program is done executing, the file should be deleted. This is what happens:</p>
  
  <p>I run the program, file does not yet exist...
  File should be created using FileWriter:</p>
  
  <pre><code>File file = new File("src/main/resources/org/avalin/optaplanner/solver/employeeShiftsScoreRules.drl");
  try (FileWriter fileWriter = new FileWriter(file))
  {
      fileWriter.write("Content...");
      fileWriter.flush();
      fileWriter.close();
  }
  catch(IOException e)
  {
          e.printStackTrace();
  }
  </code></pre>
  
  <p>And then I have this code:</p>
  
  <pre><code>private static synchronized Solver buildSolver()
  {
      SolverFactory solverFactory = 
      SolverFactory.createFromXmlResource(SOLVER_CONFIG_XML);
      return solverFactory.buildSolver();
  }
  </code></pre>
  
  <p>The filewriting is also wrapped in a synchronized method, but I assume that since they're not directly accessing the same variable, they have no effect what so ever. The file is being read from the SOLVER_CONFIG_XML seen above.</p>
  
  <p>When the program ends, it deletes the file on the path given, so that when it runs next time it will be created accordingly to parameters given to the program.</p>
  
  <hr>
  
  <p>Now this is what happens...
  The first time I run the program I get an error, saying the file isn't written. </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IllegalArgumentException: The scoreDrl (org/avalin/optaplanner/solver/employeeShiftsScoreRules.drl) does not exist as a classpath resource in the classLoader </p>
  </blockquote>
  
  <p>I can make prints right after filewriting, that concludes the method HAS run through the first time around, but for some reason, the file is not "created" anyway, before the program ends executing the first time around...</p>
  
  <p>The second time, program runs fine, as the file was created before it gets to the exception?</p>
  
  <p>Is there a way to make sure the file is "completely written" before the next part of my program executes? The file differs in length each time, as it is dynamically created from what the user inputs, so I can't check on that. I would assume it would be completely written as it did execute the prints I made after fileWriter.close() but apparently not so.</p>