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
Joshua Cranmer - 19 Apr 2007 02:53 GMT
> I thought this would be straight-forward but I haven't been able to find an
> answer.
[quoted text clipped - 12 lines]
>
> 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.
Tom Hawtin - 19 Apr 2007 04:00 GMT
> 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
news.rcn.com - 19 Apr 2007 21:35 GMT
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
>> 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
[quoted text clipped - 4 lines]
>
> Tom Hawtin
Brandon McCombs - 20 Apr 2007 01:02 GMT
> I thought this would be straight-forward but I haven't been able to find an
> answer.
[quoted text clipped - 12 lines]
>
> 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.