19greg96
19greg96

Reputation: 2591

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.

Upvotes: 0

Views: 1494

Answers (1)

JB Nizet
JB Nizet

Reputation: 691943

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.

Upvotes: 4

Related Questions