Java ByteBuffer to String

后端 未结 10 1591
一生所求
一生所求 2020-12-07 21:30

Is this a correct approach to convert ByteBuffer to String in this way,

String k = \"abcd\";
ByteBuffer b = ByteBuffer.wrap(k.getBytes());
String v = new Str         


        
10条回答
  •  轮回少年
    2020-12-07 22:07

    There is simpler approach to decode a ByteBuffer into a String without any problems, mentioned by Andy Thomas.

    String s = StandardCharsets.UTF_8.decode(byteBuffer).toString();
    

提交回复
热议问题