how to open data file contained in jar with JFileChooser

Discussion in 'Java' started by news.rcn.com, Apr 19, 2007.

  1. news.rcn.com

    news.rcn.com Guest

    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
     
    news.rcn.com, Apr 19, 2007
    #1
    1. Advertisements

  2. 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.
     
    Joshua Cranmer, Apr 19, 2007
    #2
    1. Advertisements

  3. news.rcn.com

    Tom Hawtin Guest

    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
     
    Tom Hawtin, Apr 19, 2007
    #3
  4. news.rcn.com

    news.rcn.com Guest

    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" <> wrote in message
    news:4626da6a$0$8750$...
    > 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
     
    news.rcn.com, Apr 19, 2007
    #4
  5. 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.
     
    Brandon McCombs, Apr 20, 2007
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    732
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,987
    muttley
    Oct 20, 2005
  3. cyberco
    Replies:
    4
    Views:
    4,021
    Roedy Green
    Feb 14, 2006
  4. Arnold Peters
    Replies:
    0
    Views:
    799
    Arnold Peters
    Jan 5, 2005
  5. O.B.
    Replies:
    0
    Views:
    526
Loading...

Share This Page