The OutPutStreamWriter write characters to an output stream, translating characters into bytes according to a specified character encoding . Each OutputStreamWriter incorporates its own CharToByteConverter , and is thus a bridge from character streams to byte streams.
Characters written to it are encoded into bytes using a specified charset. The encoding used by an OutputStreamWriter may be specified by name, by providing a CharToByteConverter , or by accepting the default encoding, which is defined by the system property file.encoding . It has alternative constructors that allow you to specify the character set (ex: ISO-Latin1, UTF-8, UTF-16 etc.) to use to convert the written characters to the bytes written to the underlying OutputStream .
When do you use a Reader/Writer and when a Stream?
- If you are dealing non-ASCII Unicode characters, e.g. Chinese, use Readers/Writers.
- If you are handling with binary data (e.g. an image) use Streams.
- If you are dealing ordinary ASCII text (the traditional 0-127 characters) you can use either.