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

difference between?  RSS feed

 
Suhas Madap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
May i know the difference between the FileInpuStream & RandomAccessFile?
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the RandomAccessFile you are able to seek to a certain point and then read from that point on, whereas the streams can only read sequentially (from start to finish).
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so if you wanted to keep a "pointer" of the last employee name read from a file, you would use randomaccessfile?

Justin
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes

You can use:

to get the current position and then you can use:

to return to that position later.

See the API for more info on those methods.

Note that the position will change if you add something to the file.
 
Pratibha Malhotra
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick Analogy to FileInputStream and RandamAccessFile would be a cassette/tape and a CD . You listen to audio on tape sequentially. whereas you can quickly jump to difference songs/sudio in case of CD.

Jumping around in RandamAccessFile can be done by using seek()


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