aspose file tools*
The moose likes I/O and Streams and the fly likes Getting filename of open file (RandomAccessFile) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Getting filename of open file (RandomAccessFile)" Watch "Getting filename of open file (RandomAccessFile)" New topic
Author

Getting filename of open file (RandomAccessFile)

Rob Marshall
Ranch Hand

Joined: Aug 17, 2009
Posts: 30
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

When you create the object you have to specify the name of the file. So just save the name then.
Rob Marshall
Ranch Hand

Joined: Aug 17, 2009
Posts: 30
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

Joined: Aug 17, 2009
Posts: 30
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting filename of open file (RandomAccessFile)