Byte streams vs Character streams

Byte streams vs Character streams


Byte streams vs Character streams: Character streams Advantages over Byte streams

Byte streams read bytes that fall under ASCII range and character streams read Unicode characters that include characters of many international languages. Being latest, introduced with JDK 1.1, the character streams are advantageous over byte streams like the inclusion of newLine() method (that is not deprecated) with BufferedReader. BufferedWriter includes a overloaded write() method that can write a whole string or a part of a string; but the writeBytes() method of DataOutputStream is not overloaded and writes a whole line (but not part).

Sometimes, byte streams are more efficient to read binary data like the files containing images and sound.

To bridge or link byte streams with character streams, there comes two classes InputStreamReader and OutputStreamWriter. Many byte streams (not all) have equivalent classes in character streams like FileInputStream equivalent FileReader and FileOutputStream equivalent to FileWriter etc.

Character streams – Reader and Writer

The character streams are capable to read 16-bit characters (byte streams read 8-bit characters). Character streams are capable to translate implicitly 8-bit data to 16-bit data or vice versa. The two super-most classes from which all character streams are derived are Reader and Writer. Following hierarchies can be referred for the list of all character streams.

Byte streams vs Character streams

Byte streams vs Character streams

4 thoughts on “Byte streams vs Character streams

Leave a Reply

Your email address will not be published. Required fields are marked *