简体   繁体   English

一起在Java中使用BufferedWriter和DataOutputStream

[英]Using BufferedWriter and DataOutputStream in java together

How can I simply write big-endian typed data into an OutputStream and still use buffering? 如何简单地将Big-endian类型的数据写入OutputStream并仍然使用缓冲? (I'm developing for android if it makes any difference) (如果有任何区别,我正在为Android开发)

I tried 我试过了

out = new BufferedWriter(new DataOutputStream(new OutputStreamWriter(sock.getOutputStream())));

but it looks like I'm in no luck, because this cannot be done. 但看起来我倒霉,因为这无法完成。 I'm new to Java. 我是Java新手。

Writers are used to write characters (text). 书写器用于书写字符(文本)。 Streams are used to write bytes (binary). 流用于写入字节(二进制)。

You can wrap a Stream with a Writer, but not the reverse. 您可以使用Writer来包装Stream,但不能相反。

If you want binary data and buffering, use a BufferedOutputStream. 如果要二进制数据和缓冲,请使用BufferedOutputStream。

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

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