Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference b/w Character streams and Byte streams  RSS feed

 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
I think this is the right forum for this question. What is the difference between character and byte streams right from the low level implementation to the high level implementation. what I actually feel is there is only one difference and that is when we use the character streams the data will be read as a character (i.e 16 bits) and when we read/write the data as byte stream then it will be done as a byte(i.e 8 bits) and there is no other difference. Can anyone help me out in explaining the whole concept.
Thanks in advance.
Shekar.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the I/O and Streams forum...
[ September 24, 2003: Message edited by: Dirk Schreckmann ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The streams deal in "uninterpreted" bytes. If a file contains six bytes, then you'll read six bytes out of it.
The Reader/Writers deal in character data, and the data is interpreted according to a particular character set encoding (either the default, or one you specify). If that character set uses 16 bits per character, then the Reader will return one character for every 2 bytes in the file. But for encodings like UTF-8, which use a variable number of bytes per character, or Latin-1, which always uses only one byte per character, the Readers and Writers will also do the right thing.
So your summary is basically correct, except that the reality is a little more complicated.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!