I try files writer as follows:
String content = "Test File Content";
- I used as like :
Files.write(path, content.getBytes(), StandardOpenOption.CREATE);
If file is not create, file is created and content is written. But If file available , the file content is Test File ContentTest File Content
and if the code is run repeat, the file content is Test File ContentTest File ContentTest File Content
...
- I used as like :
Files.write(path, content.getBytes(), StandardOpenOption.CREATE_NEW);
,
If file is not create, file is created and than thow an exception as follow:
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 ...
How to overwrite file via java new I/O?