how to open data file contained in jar with JFileChooser

N

news.rcn.com

I thought this would be straight-forward but I haven't been able to find an
answer.

I package sample data (image files) in a jar with my application. I want to
let the user select from these and open them using a JFileChooser. But I
don't know how to expose the 'directory tree' within the jar file to the
JFileChooser.

Is this possible?

If not, is there a way to access these file programatically? Then I could
create a menu selection that would open the files and load them. I'd rather
let the user browse though because then I can change the file set with
mucking with other parts of the package.

Thanks a lot
 
J

Joshua Cranmer

news.rcn.com said:
I thought this would be straight-forward but I haven't been able to find an
answer.

I package sample data (image files) in a jar with my application. I want to
let the user select from these and open them using a JFileChooser. But I
don't know how to expose the 'directory tree' within the jar file to the
JFileChooser.

Is this possible?

If not, is there a way to access these file programatically? Then I could
create a menu selection that would open the files and load them. I'd rather
let the user browse though because then I can change the file set with
mucking with other parts of the package.

Thanks a lot

To access files within a JAR file, look at the java.util.jar API. You
would probably have to override or rewrite JFileChooser to get the
interface, though.
 
T

Tom Hawtin

Joshua said:
To access files within a JAR file, look at the java.util.jar API. You
would probably have to override or rewrite JFileChooser to get the
interface, though.

Can you not do it by implementing FileView and FileSystemView, and
extending File?

Tom Hawtin
 
N

news.rcn.com

I thank both responds for their suggestions which together I think will
solve the problem (though the solution seems non trivial.) Basically, it
seems I should build a ZipFileSystemView that can analyze a zip ( or jar)
file and present it to the outside world as its own little file system.

Should be fun.

Thanks,

jim
 
B

Brandon McCombs

news.rcn.com said:
I thought this would be straight-forward but I haven't been able to find an
answer.

I package sample data (image files) in a jar with my application. I want to
let the user select from these and open them using a JFileChooser. But I
don't know how to expose the 'directory tree' within the jar file to the
JFileChooser.

Is this possible?

If not, is there a way to access these file programatically? Then I could
create a menu selection that would open the files and load them. I'd rather
let the user browse though because then I can change the file set with
mucking with other parts of the package.

Thanks a lot

A user shouldn't have any reason, in my opinion, to dig into the
supplied JAR file. Why not package the JAR into a larger package (like a
Windows installer for example or just a ZIP file) that contains a folder
with your sample images? Then you don't have to do anything to your code
and the users don't have to dig into your JAR to access sample files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top