public class CharsetTransform { public static void main(String[] args) throws Exception {// Properties properties = System.getProperties();// for (Object key : properties.keySet()) {// String name = (String) key;// System.out.println(name + "------>" + properties.get(key));// } //file.encoding------>UTF-8 // 创建简体中文对应的Charset Charset cn = Charset.forName("UTF-8"); // 获取cn对象对应的编码器和解码器 CharsetEncoder cnEncoder = cn.newEncoder(); CharsetDecoder cnDecoder = cn.newDecoder(); // 创建一个CharBuffer对象 CharBuffer cbuff = CharBuffer.allocate(20); cbuff.put('随'); cbuff.put('便'); cbuff.flip(); // 将CharBuffer中的字符序列转换成字节序列 ByteBuffer bbuff = cnEncoder.encode(cbuff); // 循环访问ByteBuffer中的每个字节 for (int i = 0; i < bbuff.capacity(); i++) { System.out.print(bbuff.get(i) + " "); } // 将ByteBuffer的数据解码成字符序列 System.out.println("\n" + cnDecoder.decode(bbuff)); }}
噜噜哒
qq_花开花谢_0