public static void main(String[] args) {
// 1. 字符串转为 ByteBuffer
ByteBuffer buffer1 = ByteBuffer.allocate(16);
buffer1.put("hello".getBytes());//仍然处于写模式
// 2. Charset
ByteBuffer buffer2 = StandardCharsets.UTF_8.encode("hello");//操作完后处于读模式
// 3. wrap
ByteBuffer buffer3 = ByteBuffer.wrap("hello".getBytes());
// 4. 转为字符串
String str1 = StandardCharsets.UTF_8.decode(buffer2).toString();
System.out.println(str1);
buffer1.flip();
String str2 = StandardCharsets.UTF_8.decode(buffer1).toString();
System.out.println(str2);
}