相关疑难解决方法(0)

将byte []转换为String然后再转换为byte []

我正在研究代理服务器.我正在获取数据byte[],我将其转换为String执行某些操作.现在当我将这个新的转换Stringbyte[]它时会导致未知问题.

所以主要是因为我需要知道如何正确地将a转换byte[]为a String然后再转换为a byte[].

我试图将转换byte[]String然后再转换回来byte[](以确保它不是我的操作导致问题).

所以它就像:

// where reply is a byte[]

String str= new String(reply,0, bytesRead);
streamToClient.write(str.getBytes(), 0, bytesRead);
Run Code Online (Sandbox Code Playgroud)

不等于

streamToClient.write(reply, 0, bytesRead);
Run Code Online (Sandbox Code Playgroud)

我的代理工作正常,当我发送byte[]没有任何转换,但当我将其转换byte[]为a String然后回到byte[]它导致问题.

有人可以帮忙吗?=]

java string bytearray

7
推荐指数
2
解决办法
4511
查看次数

标签 统计

bytearray ×1

java ×1

string ×1