raviteja
raviteja

Reputation: 5

How to choose RandomAccessFile dynamically?

I had written a program using RandomAccessFile class to read binary data. The code is as follows

RandomAccessFile in = new RandomAccessFile('BOT.GRD', "r");
in.read(a);

Now I want to choose file dynamically rather than providing directly as above. I tried a lot and I was unable to do that. Can any one help me on this?

Upvotes: 0

Views: 112

Answers (2)

Perception
Perception

Reputation: 80603

Assign the filename to a variable and pass that into the RandomAccessFile constructor:

String filename = "somedynamicname.grd";
RandomAccessFile file = new RandomAcessFile(filename, "r");
file.read(a);

Upvotes: 0

Andrew Thompson
Andrew Thompson

Reputation: 168825

Offer the user a JFileChooser to select the File. See How to Use File Choosers for more details & examples.

Upvotes: 1

Related Questions