dcsimg

How do I map a file into memory using the New I/O capabilities in Java 1.4?

John Zukowski

FileInputStream input = new FileInputStream(filename);
FileChannel channel = input.getChannel();
int fileLength = (int)channel.size();
MappedByteBuffer buffer = 
  channel.map(FileChannel.MAP_RO, 0, fileLength);