java鍏ラ棬 -- 缂栫爜鍜岃В鐮�

/*

* 缂栫爜鍜岃В鐮�:

* 缂栫爜锛氬皢瀛楅潰閲忎俊鎭浆鎹㈡垚缂栫爜淇℃伅;

* 瑙g爜锛氬皢瑙g爜淇℃伅缂栫▼鍙槄璇讳俊鎭細

*

* 娉ㄦ剰锛氱紪鐮佸拰瑙g爜涓�鑸娇鐢ㄥ悓涓�鐨勭爜琛紝鍚﹀垯瀹规槗鍑虹幇涔辩爜锛�

* 鍑虹幇涔辩爜涔嬪悗涓嶄竴瀹氳兘澶熻杩樺師锛屾瘮濡傚瓧绗︿腑瀛樺湪鏈夋湭鐭ュ瓧绗�

* 缂栫爜鍜岃В鐮佺殑鏃跺�欙紝榛樿鐨勭爜琛ㄦ槸utf-16(涓枃鑻辨枃閮芥槸2涓瓧鑺�)

*

*/

package com.michael.lin;

import java.io.UnsupportedEncodingException;

import java.util.Arrays;

public class Demo06 {

public static void main(String[] args) throws UnsupportedEncodingException{

String str = "涓浗";

//缂栫爜

byte[] buf = str.getBytes("utf-8"); //鏍规嵁骞冲彴榛樿鐨勫瓧绗︾紪鐮佹潵鑾峰彇瀛楃鐨勫瓧鑺傜郴鍒楋紝涓枃绯荤粺鐨勫瓧绗﹂泦鏄痝bk

System.out.println(Arrays.toString(buf));

//瑙g爜鍚庣殑瀛楃涓�

String str1 = new String(buf,"utf-8");

System.out.println(str1);

}

}

你可能感兴趣的:(java鍏ラ棬 -- 缂栫爜鍜岃В鐮�)