import java.io.*; import java.nio.*; import java.io.FileInputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class JavaByteBuffer { 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(1024); fchannel.read(bytebuf); bytebuf.flip(); System.out.print("Contents of file "); while (bytebuf.hasRemaining()) { System.out.print((char) bytebuf.get()); } } }