bytebuffer和字符串互相转换
//字符串转bytebuffer方法一,返回写模式,想要读取数据需要先调用buffer.flip();不推荐
ByteBuffer buffer = ByteBuffer.allocate(10);
buffer.put("hello".getBytes());
//字符串转bytebuffer方法二,此方法直接返回读模式,可直接读取数据
ByteBuffer hello = StandardCharsets.UTF_8.encode("hello");
//字符串转bytebuffer方法三,此方法直接返回读模式,可直接读取数据,和方法二一样,直接为读模式
ByteBuffer wrap = ByteBuffer.wrap("hello".getBytes());
//bytebuffer转字符串
String decode = StandardCharsets.UTF_8.decode(buffer).toString();