• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt regarding DataInputStream and FileInputStream

 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.


the above code is working fine.

but my doubt

available() is FileInputStream method , how come it can be accessed by DataInpuStream object dis??


2. So the below code should work fine then, but its not working
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A DataInputStream is an InputStream (an OO isA relationship) since it is derived from it and therefore the available() method exists.

Note - InputStream.available() is a poorly named method since the result is the number of bytes that can be read without blocking and not the length of the stream. It should not be used to find the length of a file or as an indication of end-of-file.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
veena joshi wrote:2. So the below code should work fine then, but its not working

ItDoesntWorkIsUseless
 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please, explain more in detail, as i did not get you.
 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.Now i got it .thanks a lot.
avaliable() is found in InputStream class so found in DataInputStream &FileOutputStream class as both extends that.

thanks a lot.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding to what Richard said: you should probably read AvailableDoesntDoWhatYouThinkItDoes. What you're doing here is basically harmless, but it's very difficult to find anything useful you can achieve, reliably, with the available() method. If you want to know the size of the file, use the File object, and call the length() method. The available() method is an evil, useless method that should be deleted from all code; it only exists to mislead people.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!