Now.Zero
Now.Zero

Reputation: 1389

printwriter vs outputstream vs outputstreamwriter in java

I'm not sure what the difference is between outputstream vs outputstreamwriter in java. Plus I see some usages Printwriter with these two class together. Are not any of these usable independently?

Upvotes: 2

Views: 3166

Answers (2)

Blokje5
Blokje5

Reputation: 5003

An Outputstream is an output stream of bytes. For example you can output it to your stdout (the static variable System.out returns an Outputstream that points to stdout). The OutputstreamWriter is a wrapper around the Outputstream specifically for character streams encoded in a certain encoding, such as utf-8. It provides utility methods for writing Strings or characters to the output.

Upvotes: 1

Chris623
Chris623

Reputation: 2532

OutputStream

OutputStream is a stream where you can work on for outputting data to any destination. It has basic functionality and allows only writing bytes to the stream.

PrintWriter and OutputStreamWriter

PrintWriter and OutputStreamWriter are helper that let you act on top of an OutputStream. For instance the PrintWriter lets you write directly Strings to the OutputStream so that you don't have to take care of writing the bytes.

Upvotes: 2

Related Questions