Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

read() method  RSS feed

 
yaswanth yash
Greenhorn
Posts: 12
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why and how Read() method of InputStream class (used as System.in.read()) is accepting more than one character at-a-time....even though it is used to read one character at-a-time...
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a look in the API documentation and I see 22 different classes just in the java.io package alone which have a read() method. To make things easier to understand, could you choose one of those classes to discuss? Otherwise the question is just too unfocused.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And by the way, welcome to the Ranch!
 
yaswanth yash
Greenhorn
Posts: 12
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup! Thnq paul....
 
santosh chaitanya
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why and how Read() method of InputStream class (used as System.in.read()) is accepting more than one character at-a-time??


The way methods receive(Or Accepts in your terminology) something from outside world is through its parameters.

As Read() method here we have as subject is not having any parameters in its signature, Your question is not making sense to me??

But, Let me tell you one thing. Its not the READ method which is accepting all the characters you write on to the stream. Rather, READ Method helps you read one byte at a time on whichever stream it is called until end of the stream is reached.

If you limit the Input Stream to accept only one character just for the sake Read() method, The fellow overloaded READ methods will have no meaning for their existence.

Thus, READ() method is written to read one byte at a time for you, Though the stream on which you call that method contains N number of characters.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!