【nio】ByteBuffer与String转换

1.String转ByteBuffer
// 方式一
ByteBuffer byteBuffer = ByteBuffer.allocate(16); 
byteBuffer.put("hello".getBytes());
// 方式二
byteBuffer = StandardCharsets.UTF_8.encode("hello");
// 方式三
byteBuffer = ByteBuffer.wrap("hello".getBytes());
2.ByteBuffer转String
String str = StandardCharsets.UTF_8.decode(byteBuffer).toString();
byteBuffer.flip();