网上 博文关于 byte[] 与 char[] 的互转写法很多都是错误的,
特此重写
if (编码 == null)
编码 = Charset.forName("UTF-8");
ByteBuffer bb = ByteBuffer.allocate(bytes.length);
bb.put(bytes);
bb.flip();
CharBuffer cb = 编码.decode(bb);
char[] cc =new char[ cb.limit()];
cb.get(cc);
return cc;
}
public static byte[] charsToBytes(char[] chars, Charset 编码) {
if (编码 == null)
编码 = Charset.forName("UTF-8");
CharBuffer cb = CharBuffer.allocate(chars.length);
cb.put(chars);
cb.flip();
ByteBuffer bb = 编码.encode(cb);
byte[] cc =new byte[ bb.limit()];
bb.get(cc);
return cc;
}