Let's look at how a File
object works.
First, say we have the following code in a file named FileTest.java:
public class FileTest {
public static void main() {
File[] files = new File("temp").listFiles();
for (File f : files) System.out.println(f.getName());
}
}
When we compile this, javac creates a file named FileTest.class. (Even Eclipse will do this; it just places the .class files in a separate folder from the .java files.) Now when we run this program, it will look for a folder named "temp" located in the same folder as the FileTest.class file.
Now suppose that we create a JAR file named filetest.jar and add FileTest.class to it. Now if we run the program from the JAR file, it will look for a folder named "temp" located in the same folder as the filetest.jar file. In other words, File
only looks for files and folders in the file system on your hard drive. It knows absolutely nothing about the contents of any files, including filetest.jar.
In order to read the contents of a JAR file, you must find a different solution. To start, you need to understand that inside a JAR file there is no such thing as "files" and "folders". A JAR file is simply a ZIP file with a few extra features. With the information you have given here so far, I believe that to solve your problem you will need to use java.util.zip.ZipFile. I suggest you start by googling for a tutorial or browing the API doc which I have linked here.