title: How to wait in the same thread while file is being written to, to finish, so we can use it
body: <p>I have a file open and write situation that crashes with EOFException once in about 20-30 times, because the file is unavailable because some other process is writing to it.</p>
  
  <p>Can I catch this exception, then somehow wait for the file write operation synchronously to end, so I can recurse the method?</p>
  
  <pre><code>File productJSON = getFileStreamPath("product" + "_" + getId() + ".json");
  if (!productJSON.exists()) {
      productJSON = getFileStreamPath("product" + ".json");
  }
  
  InputStream jsonStringsFileInputStream;
  try {
      jsonStringsFileInputStream = new FileInputStream(productJSON);
  
      HashMap&lt;String, Map&gt; that = new JSONToProductParser().convertThisToThat(jsonStringsFileInputStream);
  
  } catch (FileNotFoundException e) {
      e.printStackTrace();
  }
  </code></pre>