import java.nio.*; import java.nio.channels.FileChannel; import java.io.*; public class CreateMapBuffer { public static void main(String[] args) throws IOException { File file=new File("FileTest.txt"); FileInputStream fin=new FileInputStream(file); FileChannel fc=fin.getChannel(); MappedByteBuffer mapByteBuff=fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length() ); while (mapByteBuff.hasRemaining()) { System.out.print((char)mapByteBuff.get()); } System.out.println(); if(mapByteBuff.isReadOnly()) { System.out.print("MappedByteBuffer is read only"); }else { System.out.print("MappedByteBuffer is not read only"); } } }