我怎么打印字节一个字节数组的内容?
我使用加密(字节)code输入字符串
,然后保存加密(字符串)在DB。
I use encrypt(byte) code for input String
and then save encrypt(String) in DB.
我得到字符串
加密解密,但我需要投字符串
到字节
不改变,因为解密得到的只是一个字节。
I get String
encrypt from DB to decrypt it, but I need to cast String
to byte
without changing because decrypt get just byte.
我用 s.getBytes();
,但它改变了它,
我需要一些code投字符串字节不改变的字符串。
谢谢你这么多。
I need some code to cast string to byte without changing the String. Thank you so much.
的getBytes()
不改变字符串,它连接codeS字符串转换成序列利用该平台的默认字符集字节。
getBytes()
doesn't change the string, it encodes string into a sequence of bytes using the platform's default charset.
为了打印字节为字符串
值的阵列,
In order to print the array of bytes as a String
value,
String s = new String(bytes);
编辑:
它似乎要打印的字符串作为字节,以便您可以用
it seems as you want to print the string as bytes, for which you can use
Arrays.toString(bytes)
请参阅此code,
String yourString = "This is an example text";
byte[] bytes = yourString.getBytes();
String decryptedString = new String(bytes);
System.out.println("Original String from bytes: " + decryptedString);
System.out.println("String represented as bytes : " + Arrays.toString(bytes));
输出
Original String from bytes: This is an example text
String represented as bytes : [84, 104, 105, 115, 32, 105, 115, 32, 97, 110, 32, 101, 120, 97, 109, 112, 108, 101, 32, 116, 101, 120, 116]