//string 轉 byte[]和byte[] 轉 string
1、不設定編碼方式
<pre name="code" class="java">String str = "Hello";
byte[] srtbyte = str.getBytes();//string 轉 byte[]
//s
String res = new String(srtbyte);//byte[] 轉 string
2、設定編碼方式
String str = "hello";
byte[] srtbyte = null;
try {
srtbyte = str.getBytes("UTF-8");//string 轉 byte[]
String res = new String(srtbyte,"UTF-8");//byte[] 轉 string
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}