views:

216

answers:

2

Hi,

Please explain byte stream and character stream files. What exactly these means , is microsoft word document is byte oriented or character oriented ?

Thanks

+1  A: 

Read this. It tells you about the difference between bytes and characters (as well as loads of other useful stuff)

dty
+4  A: 

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.

kgiannakakis
Thanks kgiannakakis,and What about .txt file ?
JavaUser
A character stream is appropriate for reading a .txt file. As I said however, you need to know the encoding of the text file.
kgiannakakis
i am asking about .txt file present in a windows OS
JavaUser
@JavaUser it doesn't matter on which OS you have your .txt file, it can be in any character encoding, and in general it is not possible to unambiguously detect the character encoding that's used in a .txt file. The most common encodings are `ISO-8859-1` and `UTF-8`.
Jesper
Your Word document might be text format if you've used one of the new XML formats :-)
dty