Mega Code Archive

 
Categories / Java / File Input Output
 

Map FileChannel to MappedByteBuffer

import java.io.FileInputStream; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; public class Main {   public static void main(String args[]) throws Exception {     String filename = args[0];     int start = 10;     int length = 20;     FileInputStream fin = new FileInputStream(filename);     FileChannel finc = fin.getChannel();     MappedByteBuffer mbb = finc.map(FileChannel.MapMode.READ_ONLY, start, length);     for (int i = 0; i < length; ++i) {       System.out.println(mbb.get(i);     }     fin.close();   } }