title: Writing and reading files on mapped drives with separate Java processes
body: <p>I have java process 1 which uses rpc to call java process 2 which creates a file on a mapped network drive. Process 1 then attempts to read the file. Usually the file is read ok but sometimes it can't find the file even though I can see that it does get created.</p>
  
  <p>Process 1, 2 and the mapped drive are each on separate Windows Server 2008 machines. Therefore the processes are on separate JVMs and separate operating systems.</p>
  
  <p>Process 2 does this sort of thing before returning (meaning that it ensures the file is written to disk before returning from the rpc call):</p>
  
  <pre><code>FileOutputStream fileOut = new FileOutputStream(new File(pdfPath));
  bufferedOut = new BufferedOutputStream(fileOut);
  // write to file
  bufferedOut.flush();
  fileOut.getFD().sync();
  bufferedOut.close();
  </code></pre>
  
  <p>Process 1 will attempt to read the file after the rpc method call returns.</p>
  
  <p>I'm sure that the file is written before process 1 attempts to read it but that some caching is taking place in either the JVM or the operating system which is preventing the process from detecting the file</p>
  
  <p>There's no error until I try to read the file and it looks like this:</p>
  
  <pre><code>java.io.IOException: G:/mydir/my file ( 1.pdf not found as file or resource.
      at com.itextpdf.text.pdf.RandomAccessFileOrArray.&lt;init&gt;(RandomAccessFileOrArray.java:113)
      at com.itextpdf.text.pdf.RandomAccessFileOrArray.&lt;init&gt;(RandomAccessFileOrArray.java:80)
      at com.itextpdf.text.pdf.PRTokeniser.&lt;init&gt;(PRTokeniser.java:112)
      at com.itextpdf.text.pdf.PdfReader.&lt;init&gt;(PdfReader.java:169)
      at com.itextpdf.text.pdf.PdfReader.&lt;init&gt;(PdfReader.java:159)
      ...
  </code></pre>