File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method read() in InputStream class

 
mark stone
Ranch Hand
Posts: 417
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when one calls the read() method, typically say in the System.in.read() then which read method is being called and from where ? because the read() method is abstract (as mentioned in the api).
the other read methods in InputStream class
read(byte[] b) and read(byte[] b, int off, int len) are not abstract though. I know that they are not being called, ijust mentioned it because my next question deals with this.
second question about the buffer b. We could access the array b ? right ? is this why this buffer has been provided so that one may access the contents of this buffer ? if not what is the purpose.
 
mark stone
Ranch Hand
Posts: 417
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List i need your help with this one.
Originally posted by mark stone:
when one calls the read() method, typically say in the System.in.read() then which read method is being called and from where ? because the read() method is abstract (as mentioned in the api).
the other read methods in InputStream class
read(byte[] b) and read(byte[] b, int off, int len) are not abstract though. I know that they are not being called, ijust mentioned it because my next question deals with this.
second question about the buffer b. We could access the array b ? right ? is this why this buffer has been provided so that one may access the contents of this buffer ? if not what is the purpose.
 
Jason Kretzer
Ranch Hand
Posts: 280
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I THINK the buffer is there so that you can have access to those bytes. You pass the array object to the read method and it fills it for you.
 
Jason Kretzer
Ranch Hand
Posts: 280
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is some code:

Hope this helps!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic