在java中通过套接字流接收错误的字节值
我尝试将文件作为字节数组读取并通过套接字连接通过网络发送, 我在从文件读取后(在发送之前)打印了字节的值,并在从套接字接收到它后打印了字节的值......这是不同的!它收到的值是错误的我不知道为什么
在发送之前采样字节: 21、 0, 52、 0 接收后的样本字节: -8, -1, -4, -1
我使用 write(byte[] b) 发送字节; OutputStream 类 并使用 read(byte[] b, int off, int len); 接收字节输入流类。
谁能帮助我吗?
I try to read a file as a byte array and send it through network over socket connection,
I printed the values of the bytes after reading from file(before sending it) and printed the values of bytes after receiving it from socket ... and it was different! it is received in wrong values I don't know why
sample bytes before sending:
21,
0,
52,
0
sample bytes after receiving:
-8,
-1,
-4,
-1
I sent the bytes using write(byte[] b); of OutputStream class
and received bytes using read(byte[] b, int off, int len); of InputStream class.
can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以尝试
打印
You can try
prints
请小心将字节和字符视为可互换的。字节已签名!
Be careful treating bytes and chars as interchangeable. Bytes are signed!