How to copy from ByteBuffer to String
1. Simple but not exactly right
simply create string with byte array from ByteBuffer
ByteBuffer buffer = ByteBuffer.allocate(1024);buffer.put(“aabcde”.getBytes());
String s =newString(buffer.array(), "");
//orString s =newString(buffer.array(), "UTF-8");
System.out.println(s);
2. More elegance way
buffer.put(“aabcde”.getBytes());byte[] bytes =newbyte[buffer.position()];buffer.flip();buffer.get(bytes);String s =newString(bytes); // or new String(bytes, "UTF-8");System.out.println(s);