简体   繁体   中英

Using BufferedWriter and DataOutputStream in java together

How can I simply write big-endian typed data into an OutputStream and still use buffering? (I'm developing for android if it makes any difference)

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.

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.

If you want binary data and buffering, use a BufferedOutputStream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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