Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

how to open data file contained in jar with JFileChooser

Thread view: 
news.rcn.com - 19 Apr 2007 01:06 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.