【发布时间】:2014-10-26 03:06:36
【问题描述】:
我有一个客户端服务器 Java 代码,客户端正在读取一个字符串“输入”,然后它应该解密它,解密函数需要一个字节数组,所以我需要将字符串转换为字节数组,这使用“getBytes()”函数完成,但似乎这个函数正在修改字符串!如何在不更改其内容的情况下将字符串转换为字节数组。
String input = inputline.substring(66, inputline.length());
System.out.println("Read message +"+input+"+");
byte[] bx = input.getBytes(Charset.forName("UTF-8"));
System.out.println("Read message +"+bx.toString()+"+");
System.out.println("Read message +"+bx+"+");
代码sn-p的输出如下:
阅读留言+[B@161cd475+
阅读留言+[B@4e25154f+
阅读留言+[B@4e25154f+
【问题讨论】:
-
我能否澄清
Read message +[B@161cd475+是否对字符串“输入”有效? -
@AlvinBunk 是的,“[B@161cd475”是需要的文本。
标签: java string type-conversion bytearray