将ByteBuffer转换为String的过程。以下是实现该过程的方法:public static String byteBufferToString(ByteBuffer buffer) { CharBuffer charBuffer = null;try { Charset charset = Charset.forName("UTF-8");CharsetDecoder decoder = charset.newDecoder();charBuffer = decoder.decode(buffer);buffer.flip()...
public static void main(String[] args){ String s = "str1|str2|str3|'\0'str21|str22|str23|'\0''\0'";//String变量 byte b[] = s.getBytes();//前两行主要是定义你的ByteBuffer,你那应该有自己的方法。ByteBuffer buffer=ByteBuffer.wrap(b);String result =decode(buffer);System...
public String decode(ByteBuffer buffer)2 { 3 System.out.println( " buffer= " + buffer);4 Charset charset = null ;5 CharsetDecoder decoder = null ;6 CharBuffer charBuffer = null ;7 try 8 { 9 charset = Charset.forName( " gb2312 "...