Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FileInputStream, DataINputStream, BufferedReader  RSS feed

 
Benjamin Bielschowsky
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys, I am beginning to learn about reading files on the disk and I see these 3 methods: FileInputStream, DataINputStream, and BufferedReader. Below I posted 2 snippets that do exactly the same thing, the first reads a text file by only using bufferedreader and the second uses all 3 methods. What's the purpose and function of each: FileInputSteam, DataInputStream, and BufferedReader, and why would I use all 3 when it seems that I could do the same thing with only BufferedReader.
Thanks!

Only using BufferedReader


Using FileInputStream, DataINputStream, and BufferedReader
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37249
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first one doesn't just use BufferedReader. It uses BufferedReader and FileReader. This is important because BufferedReader doesn't have a constructor that can deal with a file.

Note that Reader classes are for character data and input stream data is for binary data.
 
Slaxmi Raj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,better to know what the differences between these.
FileInputStream: Read the contents of file as a stream of bytes.
DataInputStream: Works with the binary data
Is a part of the filtered Streams
Consumes less amount of memory space being it is a binary stream
Data to be handled is limited.
BufferedReader: Works with character data
Is not part of the filtered Streams.
Consumes more amount of mamory space being it is a character stream.
Number of characters to be handled has wide scope.

this may helpful to you.
Thank you.


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