import java.io.*; import java.nio.*; import java.io.FileInputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class ByteBufferRewind { public static void main(String[] args) throws IOException { FileInputStream aFile = new FileInputStream("bharat.txt"); FileChannel inChannel = aFile.getChannel(); ByteBuffer buf = ByteBuffer.allocate(55); int bytesRead = inChannel.read(buf); buf.flip(); System.out.print("Without rewind the content of buffer :\n"); while (buf.hasRemaining()) { System.out.print((char) buf.get()); } buf.rewind(); System.out.print("\nAfter using rewind content of buffer : \n"); while (buf.hasRemaining()) { System.out.print((char) buf.get()); } aFile.close(); } }