//测试
String testString = "测试数据";
byte[] stringByte = testString.getBytes();
byte[] base64Byte = Base64.decodeBase64(testString);
System.out.println("原字符串:"+testString);
System.out.println("stringByte:"+stringByte.toString());
System.out.println("base64Byte:"+base64Byte.toString());
//还原字符串
System.out.println("还原stringByte:"+new String(stringByte));
System.out.println("还原base64Byte:"+Base64.encodeBase64String(base64Byte));
输出结果如下:
原字符串:测试数据
stringByte:[B@589f1e7b
base64Byte:[B@6ea0724
还原stringByte:测试数据
还原base64Byte:
结论:像上面这样常用的字符串获取字节可以用String.getBytes()获取,不要使用Base64编码工具,Base64编码提供的是将Base64编码的字节转字符串使用,常用字符串不适用。