I am mapping a file("sample.txt") to memory using
sample.txt (The requested operation
cannot be per formed on a file with a
user-mapped section open)
File f = new File("sample.txt");
RandomAccessFile raf = new RandomAccessFile(f,"rw");
FileChannel fc = raf.getChannel();
MappedByteBuffer mbf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
FileOutputStream fos = new FileOutputStream(f);
A mapped byte buffer and the file mapping that it represents remain valid until the buffer itself is garbage-collected.
System.gc()? Even that's only a suggestion to the VM.