关于ByteBuffer,如何将ByteBuffer转化为String?
ByteBuffer buf = ByteBuffer.allocateDirect(8);
方法一:(打印为空)
CharBuffer cbuf = buf.asCharBuffer();
//cbuf.flip();
String s = cbuf.toString();
System.out.println(s);
方法二:(打印为乱码)
for(int i=0;i<4;i++)
{
msg+=buf.getChar(i);
System.out.println(msg);
}
或是如何读取SocketChannel中的内容?