I want to copy the content of file \'A\' to file \'B\'. after the copying is done I want to clear the content of file \'A\' and want to write on it from its beginning. I can
using : New Java 7 NIO library, try
if(!Files.exists(filePath.getParent())) {
Files.createDirectory(filePath.getParent());
}
if(!Files.exists(filePath)) {
Files.createFile(filePath);
}
// Empty the file content
writer = Files.newBufferedWriter(filePath);
writer.write("");
writer.flush();
The above code checks if Directoty exist if not creates the directory, checks if file exists is yes it writes empty string and flushes the buffer, in the end yo get the writer pointing to empty file