title: Is java.io.FileDescriptor#sync() specific to a single FileDescriptor
body: <p>I am looking to force synchronisation to disk after files are written at certain points in my application. Since it runs on Linux, I could get away with just running</p>
  
  <pre><code>Runtime.getRuntime().exec("sync");
  </code></pre>
  
  <p>However, I would rather not introduce Linux specific system calls and would rather use</p>
  
  <pre><code>java.io.FileDescriptor#sync();
  </code></pre>
  
  <p>However, I use Apache VFS to perform operations on the local file system and to my knowledge it does not provide access to the underlying file descriptor. But do I need access to the actual file descriptor that was just written to to force synchronization? Could I not just use any FileDescriptor to call sync for the same effect, for example</p>
  
  <pre><code>FileDescriptor.in.sync();
  </code></pre>
  
  <p>Would that be a valid approach, and would the results match that of calling sync in Linux?</p>
  
  <p>Just in case anyone knows if / how it is possible to get access to the underlying FileDescriptor in VFS, it would be useful to know as well.</p>
  
  <p>Edit: it appears that</p>
  
  <pre><code>FileDescriptor.in.sync();
  </code></pre>
  
  <p>does not want to work on Linux (although it works on my Windows machine when run from Eclipse), but</p>
  
  <pre><code>new FileOutputStream(new File("anyfile")).getFD().sync();
  </code></pre>
  
  <p>definitely works and the results of calling this match the results of calling the Linux sync command directly. However, it involves opening and closing a redundant file output stream, so it's not exactly ideal. Any other reason this might be a bad idea, as it does seem to work? Is there some other way to get a FileDescriptor that can be used to sync?</p>