我怎么打印字节一个字节数组的内容? [英] how do I print the contents of an array of bytes as bytes?

查看:951
本文介绍了我怎么打印字节一个字节数组的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用加密(字节)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]

这篇关于我怎么打印字节一个字节数组的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆