Accessing files within JAR archive

From: Bert Sierra (bert_sierra_at_mac.com)
Date: 10/30/03


Date: Thu, 30 Oct 2003 02:30:09 -0700

Howdy --

I'm fairly new to Java, so I'm easily stumped. The question is: How do
I access a file within a JAR archive from a Java program?

I have a simple test program, shown below, which illustrates the problem:

   import java.io.*;
   import java.util.*;

   public class FileTest {
    
       public static void main (String args[]) {
           File file = new File("test.gif");
           System.out.println("exists = " + file.exists());
           System.out.println("length = " + file.length());
       }

   }

If I store the test.gif file outside the JAR archive, in the same
directory as the JAR archive, everything runs fine -- the file exists
and I get the proper length. If I store the test.gif file in the JAR
archive, it can't be found and length()==0. None of the Java texts I
have on hand seem to address this issue.

TIA...

-- Bert Sierra
   bert_sierra@mac.com



Relevant Pages

  • Re: Problem With Crypt::CBC
    ... is later read in by a Java program. ... continue using the passwords and vectors I'm using (both 8 bytes, ... use the hash, then the Java program on the other end will not be able to ...
    (comp.lang.perl.misc)
  • Re: deadlock and thread
    ... i have "main" java program usually called as midlet, ... other java programs which is called by the main program to perform ... several task such as sending and receiving sms etc. ... As near as I can tell, in a MIDlet you have access to the same Thread class available in regular Java apps. ...
    (comp.lang.java.programmer)
  • Re: How to interact with a Live java process from php?
    ... This service can only be accessed from a java program on the backend, and this program, unfortunately, is a 24/7 live process. ... My teammate is going to write a php program to handle the front end request, so my question is that, is it possible for such a design to work? ... I'll guess the "live 24/7" backend java process is a "java servlet" ...
    (comp.lang.php)
  • Re: Problem With Crypt::CBC
    ... My Perl script has to output data that ... is later read in by a Java program. ... use the hash, then the Java program on the other end will not be able to ...
    (comp.lang.perl.misc)
  • Re: How to compare the speed between a Java program and its original Fortran version program?
    ... I have translated an old Fortran program into Java program, ... Coughing up a meager translation of a FORTRAN program to Java, then running meaningless benchmarks to try to figure out if you did anything useful is a huge disservice to your customer. ...
    (comp.lang.java.programmer)