把byte转化成string,必须经过编码。
例如下面一个例子:
importjava.io.UnsupportedEncodingException; publicclass test{ publicstatic void main(String g[]) { Strings = "12345abcd"; byteb[] = s.getBytes(); Stringt = b.toString(); System.out.println(t); } }
publicclass test{ publicstatic void main(String g[]) { Strings = "12345abcd"; byteb[] = s.getBytes(); try{ Stringt = new String(b); System.out.print(t); }catch (Exception e) { e.printStackTrace(); } } }
Stringstr = "String"; byte[]byte1 = str.getBytes(); Stringstr1 = new String(byte1); byte[]byte2 = str1.getBytes(); Stringstr2 = new String(byte2); System.out.println("str<<<"+ str); System.out.println("byte1<<<"+ byte1); System.out.println("str1<<<"+ str1); System.out.println("byte2<<<"+ byte2); System.out.println("str2<<<"+ str2);