I use MappedByteBuffer to write file in linux.
File file = new File("testFile");
RandomAccessFile raf = new RandomAccessFile(file, "rw");
FileChannel fc = raf.getChannel();
MappedByteBuffer mbf = fc.map(FileChannel.MapMode.READ_WRITE, 0, file.length());
mbf.put(buffer);
If testFile has write 500MB, and write the 500MB data twice, it takes 1s.but when I rm testFile, write the 500MB data, it takes 4s.
Why override a file is faster than write a new file? How can I write a new file as faster as override a file?