//string 转 byte[]和byte[] 转 string1、不设定编码方式
<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(); }