import java.io.*; import java.nio.*; import java.io.FileInputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class ByteBufferCapacity { public static final int size = 1024; public static void main(String[] args) throws Exception { FileInputStream finStream = new FileInputStream(args[0]); System.out.println("Given file name :" + args[0]); FileChannel fchannel = finStream.getChannel(); ByteBuffer bytebuf = ByteBuffer.allocate(size); fchannel.read(bytebuf); System.out.println("Capacity of ByteBuffer : " + bytebuf.capacity()); } }