Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between OutputStream and Writer?

Can someone explain me the difference between OutputStream and Writer? Which of these classes should I work with?

like image 974
Ani Avatar asked May 30 '12 12:05

Ani


People also ask

What is the difference between reader/writer and InputStream OutputStream?

The major difference between these is that the input/output stream classes read/write byte stream data. Whereas the Reader/Writer classes handle characters. The methods of input/output stream classes accept byte array as parameter whereas the Reader/Writer classes accept character array as parameter.

What is an OutputStream?

1.2 OutputStream: OutputStream is an abstract class of Byte Stream that describes stream output and it is used for writing data to a file, image, audio, etc. Thus, OutputStream writes data to the destination one at a time.

What does OutputStream write do?

The write method of OutputStream calls the write method of one argument on each of the bytes to be written out. Subclasses are encouraged to override this method and provide a more efficient implementation. If b is null , a NullPointerException is thrown.

What is the diff between the reader Writer class hierarchy and the InputStream OutputStream class?

What is the diff between the Reader/Writer class hierarchy and the InputStream/OutputStream Class? The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented. Most of the functionality available for byte streams is also provided for character streams.


1 Answers

Streams work at the byte level, they can read (InputStream) and write (OutputStream) bytes or list of bytes to a stream.

Reader/Writers add the concept of character on top of a stream. Since a character can only be translated to bytes by using an Encoding, readers and writers have an encoding component (that may be set automatically since Java has a default encoding property). The characters read (Reader) or written (Writer) are automatically converted to bytes by the encoding and sent to the stream.

like image 146
Vincent Robert Avatar answered Oct 10 '22 05:10

Vincent Robert