title: process cannot access file because it is being used by another process
body: <p>Though there are lot of questions like this on stackoverflow, but for me it is giving error while writing very fast to file, this method is called around 180 times in a minutes to write data to file. and when frequency of writing is very fast then it gives error as :</p>
  
  <pre><code>java.nio.file.FileSystemException: C:\dropcopy\DGCX_Report_Files\TradeReport_18072018.csv: The process cannot access the file because it is being used by another process.
  
  at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
  at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
  at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
  at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
  at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
  at java.nio.file.Files.newOutputStream(Files.java:216)
  at java.nio.file.Files.write(Files.java:3292)
  at com.algo.fix.common.TradeFileManager.appendInFile(TradeFileManager.java:542)
  at com.algo.fix.common.TradeFileManager.persistExecutions(TradeFileManager.java:469)
  at com.algo.fix.common.TradeFileManager.processTradeCaptureReport(TradeFileManager.java:768)
  at com.algo.fix.common.BaseApplication.onMessage(BaseApplication.java:129)
  at quickfix.fix50sp2.MessageCracker.crack11(MessageCracker.java:253)
  at quickfix.fix50sp2.MessageCracker.crack(MessageCracker.java:217)
  at com.algo.fix.common.BaseApplication.fromApp(BaseApplication.java:97)
  at quickfix.Session.fromCallback(Session.java:1818)
  at quickfix.Session.verify(Session.java:1762)
  at quickfix.Session.verify(Session.java:1833)
  at quickfix.Session.next(Session.java:1030)
  at quickfix.Session.next(Session.java:1173)
  at quickfix.mina.SingleThreadedEventHandlingStrategy$SessionMessageEvent.processMessage(SingleThreadedEventHandlingStrategy.java:151)
  at quickfix.mina.SingleThreadedEventHandlingStrategy.block(SingleThreadedEventHandlingStrategy.java:101)
  at quickfix.mina.SingleThreadedEventHandlingStrategy.lambda$blockInThread$0(SingleThreadedEventHandlingStrategy.java:133)
  at quickfix.mina.SingleThreadedEventHandlingStrategy$ThreadAdapter$RunnableWrapper.run(SingleThreadedEventHandlingStrategy.java:244)
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>but after this error , it resumes again to writing. skipping some data to file.
  my code to write to file is :</p>
  
  <pre><code>try{
          String data = sb.toString();
          byte[] dataByte= data.getBytes();
          Files.write(file, dataByte, StandardOpenOption.APPEND);                              
          Files.write(file, System.getProperty("line.separator").getBytes(), StandardOpenOption.APPEND);
          log.info("Wrote to file.");
      } catch(Exception e ){
          log.info("Not able to write to file.");
          e.printStackTrace();
      }
  </code></pre>