import java.io.*; import java.nio.*; import java.io.FileInputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class ByteBufferLimit { public static void main(String[] args) throws IOException { FileInputStream InStream = new FileInputStream("test.txt"); FileChannel fchannel = InStream.getChannel(); ByteBuffer byteBuf = ByteBuffer.allocate(48); int bytesRead = fchannel.read(byteBuf); System.out.println("Limit of buffer at writing mode : " + (byteBuf.limit())); byteBuf.flip(); while (byteBuf.hasRemaining()) { System.out.print((char) byteBuf.get()); } System.out.println("\n"); System.out.println("Limit of buffer at reading mode : " + (byteBuf.limit())); } }