import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; public class MMapTest { public static void main(String[] args) throws IOException, InterruptedException { File f = File.createTempFile("test", ".mmap"); RandomAccessFile raf = new RandomAccessFile(f, "rw"); raf.write("Test file\n".getBytes("UTF-8")); raf.getFD().sync(); long t0 = f.lastModified(); Thread.sleep(1000); FileChannel channel = raf.getChannel(); MappedByteBuffer buf = channel.map(MapMode.READ_WRITE, 0, f.length()); buf.put("Mapd".getBytes("UTF-8")); long t1 = f.lastModified(); buf.force(); long t2 = f.lastModified(); channel.close(); long t3 = f.lastModified(); System.err.println("t0 = " + t0); System.err.println("t1 = " + t1); System.err.println("t2 = " + t2); System.err.println("t3 = " + t3); raf = new RandomAccessFile(f, "r"); System.err.println("file = " + raf.readLine()); } }