• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting filename of open file (RandomAccessFile)

 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm sure that this has been covered somewhere, but I've been unable to find it. What I want to be able to do is create a list of RandomAccessFiles (I'm using them for doing binary searches on sorted, fixed record length, text files). But since I will have a list of them, I'm trying to figure out how to get the name of the file from the RandomAccessFile object. I don't see a getName() method. Is there another way?

Thanks,

Rob
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create the object you have to specify the name of the file. So just save the name then.
 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Yeah, I thought of that, but also wondered if there wasn't some way to get to the filename from the object so that I wouldn't have to do that.

Thanks,

Rob
 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, well being new to Java I'm not sure if this is the best way, but here's what I did:

Then when I open the files I do:

I was assuming that I needed to use "new" for everything, is that correct?

Then to iterate through them to close them:

Always open for critique and suggestions

Thanks,

Rob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic