Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Byte Stream and Character stream

Please explain what Byte streams and Character streams are. What exactly do these mean? Is a Microsoft Word document Byte oriented or Character oriented?

Thanks

like image 908
JavaUser Avatar asked Jun 10 '10 11:06

JavaUser


People also ask

What is difference between byte and character?

A byte is by convention and POSIX definition eight bits. A bit is a binary digit (i. e. the fundamental 1 or 0 that is at the base of nearly all digital computing). A character is often one byte and in some contexts (e. g. ASCII) can be defined to be one byte in length.

What is character stream?

Character streams are like byte streams, but they contain 16-bit Unicode characters rather than eight-bit bytes. They are implemented by the Reader and Writer classes and their subclasses.

Why does Java define both byte and character stream?

Modern versions of Java define two types of streams: byte and character. (The original version of Java defined only the byte stream, but character streams were quickly added.) Byte streams provide a convenient means for handling input and output of bytes. They are used, for example, when reading or writing binary data.

What is the difference between byte oriented IO and character oriented IO?

Character oriented reads character by character while byte oriented reads byte by byte. Character oriented streams use character encoding scheme(UNICODE) while byte oriented do not use any encoding scheme.


1 Answers

A stream is a way of sequentially accessing a file. A byte stream access the file byte by byte. A byte stream is suitable for any kind of file, however not quite appropriate for text files. For example, if the file is using a unicode encoding and a character is represented with two bytes, the byte stream will treat these separately and you will need to do the conversion yourself.

A character stream will read a file character by character. A character stream needs to be given the file's encoding in order to work properly.

Although a Microsoft Word Document contains text, it can't be accessed with a character stream (it isn't a text file). You need to use a byte stream to access it.

like image 171
kgiannakakis Avatar answered Sep 18 '22 14:09

kgiannakakis