简体   繁体   English

和谐使用BufferedReader和DataInputStream

[英]Using BufferedReader and DataInputStream in harmony

I've been poking around the internet for quite a while now, and I was wondering how I could use BufferedReader and DataInputStream together without opening a different port. 我已经在互联网上闲逛了一段时间,我想知道如何在不打开其他端口的情况下一起使用BufferedReader和DataInputStream。 I've tried to stream images, but as the buffered reader stores extra bytes, it creates a corrupt image. 我尝试流式传输图像,但是由于缓冲的读取器存储了额外的字节,因此会创建损坏的图像。 When I attempt to use DataInputStream.read(), I can't read full lines of text as easily. 当我尝试使用DataInputStream.read()时,我无法轻松读取整行文本。 Is there some sort of solution for my problem? 我的问题有某种解决方案吗?

DataInputStream.readLine(), and yes I know it's deprecated. DataInputStream.readLine(),是的,我知道它已被弃用。 The real solution is not to use lines in your protocol. 真正的解决方案是不要在协议中使用行。 Use readUTF() for example. 例如,使用readUTF()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM