• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why only byte stream and character stream?  RSS feed

 
s sivaraman
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i'm reading basicIO in java where i found only two streams byte and character ,while both buffered.
i wonder why only this two type of streams why not any other type of stream???


Thank you
sivaraman.s
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What type of streams do you envision--there really are only binary and text.

IMO: there is only need for 1--binary.
 
s sivaraman
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
i dont know what do you mean by binary and text.
so far as what i read , i infer that there are two streams byte and character.
correct me i'm wrong? could you!
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Byte is a binary stream and character are text streams. When you think about it, anything in the computer is only represented by "on" and "off" states in memory, so realistically all things other than a binary, byte, stream are just a formatting construct laid over a binary, byte, stream.

s sivaraman wrote:Thanks for the reply.
i dont know what do you mean by binary and text.
so far as what i read , i infer that there are two streams byte and character.
correct me i'm wrong? could you!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A computer can really only work with bits and bytes - binary data. The memory (RAM) and harddisk of a computer can only store bytes.

Text is represented in the computer's memory by using numbers. We use a character encoding to determine what number means what text character. For example, if we use the ASCII character encoding, then A = 65, B = 66, C = 67, etc. When a computer stores text in memory on in a file, then it stores the numbers - and through the character encoding we know what these numbers mean. There are different character encodings besides ASCII. Other character encodings that are used frequently are UTF-8, UTF-16 and ISO-8859-1. Note that not all character encodings use exactly 1 byte for each character. For example UTF-8 is a variable-length character encoding; it uses between 1 and 4 bytes to store a character.

Java has two kinds of classes for I/O: streams and readers / writers.

Streams: class java.io.InputStream, class java.io.OutputStream and their subclasses, are for reading and writing binary data - bytes. They just read and write directly the numbers that are stored.

Readers and writers: class java.io.Reader, class java.io.Writer and their subclasses, are for reading and writing text. They are just a wrapper around InputStream and OutputStream, using a character encoding to convert characters to bytes and vice versa.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jester, ever consider writing tutorials? :=)
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jester???
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!