JAVA,将byte转换为String

byte 转 String

 ByteBuffer byteBuffer = ByteBuffer.allocate(4*1024);
          byteBuffer.put("abcdefghijk".getBytes());
//        System.out.println(Byte.toString(byteBuffer.get()));
//        System.out.println(byteBuffer.get()+"");
//        System.out.println(new String(new byte[]{byteBuffer.get()}));

被注释掉的三行代码分别单独执行,输出结果分别为:
97 (注意,是String类型)
97 (注意,是String类型)
a
所以,byte转String,一般选用new String(new byte[]{byteBuffer.get()})

你可能感兴趣的:(Java基础)