import java.nio.*; import java.nio.ByteBuffer; public class BytePutChar { public static void main(String[] args) { ByteBuffer bytebuf = ByteBuffer.allocate(256); bytebuf.putChar('B'); bytebuf.putChar('h'); bytebuf.putChar('a'); bytebuf.putChar('r'); bytebuf.putChar('a'); bytebuf.putChar('t'); System.out.println(bytebuf); bytebuf.flip(); System.out.println("Character data in byte buffer : "); while (bytebuf.hasRemaining()) { System.out.print(bytebuf.getChar()); } } }