可以使用ByteBuffer的get()方法获取每个字节,然后将其转换为字符,最后拼接成字符串。示例代码如下: ```java ByteBuffer buffer = ByteBuffer.allocate(10); buffer.put("hello".getBytes()); buffer.flip(); StringBuilder sb = new StringBuilder(); while (buffer.hasRemaining()) { sb.append((char) buffer.get()); } String str = sb.toString(); System.out.println(str); // 输出:hello ``` 另外,也可以使用Charset类将ByteBuffer转换为字符串,示例代码如下: ```java ByteBuffer buffer = ByteBuffer.allocate(10); buffer.put("hello".getBytes()); buffer.flip(); Charset charset = Charset.forName("UTF-8"); String str = charset.decode(buffer).toString(); System.out.println(str); // 输出:hello ```