Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileInputStream vs. Random Access File (Read Performance)

 
Mark Mescher
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello out there,
I have a little question to Random Access Files (I have never used them since now).
I have to read very large files, since now I'm doing this with FileInputStreams. Now I have the problem that in some cases I dont need the first bytes (Megabytes...Gigabytes...very large files) of a file.

Which solution would you prefer? I could use a Inputstream and fast forward in this stream the first bytes or alternatively I could use a Random Access File and jump directly to the startpoint I need. Which way is more performant?
Thanx
Bye
Mark
 
Joe Ess
Bartender
Posts: 9339
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RandomAccessFile.seek() will be several times faster than FileInputStream.skip(). This is because RandomAccessFile moves the file pointer directly to the requested offset whereas FileInputStream will read and discard all the data up to the offset.
 
Mark Mescher
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK thank you than I will try it that way.
Bye
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic