方法一:String类转换
1 2 3 4 5 6 7 8 9 10 11 12 |
public static void main(String[] args) { String string = "那啥快看 791202.com"; //string 转 byte[] byte[] bytes = string.getBytes(); //byte[]转string String s = new String(bytes); System.out.println("Decoded String : " + s); } |
方法二:Base64转换
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public static void main(String[] args) { byte[] bytes = "那啥快看 791202.com".getBytes(); //byte[]转string String encoded = Base64.getEncoder().encodeToString(bytes); //string 转 byte[] byte[] decoded = Base64.getDecoder().decode(encoded); System.out.println( new String(decoded) ); } |