Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to open data file contained in jar with JFileChooser

Reply
Thread Tools

how to open data file contained in jar with JFileChooser

 
 
news.rcn.com
Guest
Posts: n/a
 
      04-19-2007
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


 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      04-19-2007
news.rcn.com wrote:
> 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.
 
Reply With Quote
 
 
 
 
Tom Hawtin
Guest
Posts: n/a
 
      04-19-2007
Joshua Cranmer wrote:
>
> 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
 
Reply With Quote
 
news.rcn.com
Guest
Posts: n/a
 
      04-19-2007
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

"Tom Hawtin" <(E-Mail Removed)> wrote in message
news:4626da6a$0$8750$(E-Mail Removed)...
> Joshua Cranmer wrote:
>>
>> 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



 
Reply With Quote
 
Brandon McCombs
Guest
Posts: n/a
 
      04-20-2007
news.rcn.com wrote:
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Executing a static non-main operation in a jar file contained withina war file O.B. Java 0 06-24-2006 05:47 PM
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM



Advertisments