• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is difference between FileInputStream and DataInputStream  RSS feed

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show the differnece between FileInputStream and DataInputStream by a code

Thanks
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say read the javadoc and then you'll easily see the differences.
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What he said ^
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to give a bit more info...

It's a common arrangement to use streams in pairs. You need one that provides the basic functionality. For instance, FileInputStream lets you read from a file.

But FileInputStream only gives you a very basic interface. When you're wanting to read numbers, Strings (or even complex Objects) rather than just bytes, that's a pain. So you use a second input stream "wrapping" the first, which gives you a more useful interface. DataInputStream is one of these. Notice that it's constructor takes another InputStream - all it's doing is translating the interface, and the "wrapped" stream is doing the real work.

Output streams come in both flavours as well.

The Java tutorials contain a lot more detail


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!