title: How to overwrite file via java nio writer?
body: <p>I try files writer as follows: </p>
  
  <pre><code>String content = "Test File Content";
  </code></pre>
  
  <ul>
  <li>I used as like : <code>Files.write(path, content.getBytes(), StandardOpenOption.CREATE);</code></li>
  </ul>
  
  <p>If file is not create, file is created and content is written. But If file available , the file content is <code>Test File ContentTest File Content</code> and if the code is run repeat, the file content is <code>Test File ContentTest File ContentTest File Content</code> ...</p>
  
  <ul>
  <li>I used as like : <code>Files.write(path, content.getBytes(), StandardOpenOption.CREATE_NEW);</code> , </li>
  </ul>
  
  <p>If file is not create, file is created and than thow an exception as follow:</p>
  
  <blockquote>
    <p>java.nio.file.FileAlreadyExistsException:
    /home/gyhot/Projects/indexing/ivt_new/target/test-classes/test_file
      at
    sun.nio.fs.UnixException.translateToIOException(UnixException.java:88)
      at
    ...</p>
  </blockquote>
  
  <p>How to overwrite file via java new I/O?</p>