listing in the file name in a directory in a jar file

F

Ferman

Hi,

I want to list in the file name in a directory in a jar file. Code example;

URL vUrl = ClassLoader.getSystemClassLoader().getResource("Templates/");
File f = new File(vUrl.getFile());
File files[] = f.listFiles();

But it hasn't give any file name. It has given empty list.

Can you help me ?

Thanks.
 
A

Andrew Thompson

Ferman said:
Hi,

I want to list in the file name in a directory in a jar file. Code example;

URL vUrl = ClassLoader.getSystemClassLoader().getResource("Templates/");
File f = new File(vUrl.getFile());
File files[] = f.listFiles();

But it hasn't give any file name. It has given empty list.

From memory you need to get the ZipEntries and iterate
through them, see..
http://java.sun.com/j2se/1.4.1/docs/api/java/util/zip/ZipFile.html#entries()

That is what I do in..
http://physci.org/applet/Ziplet.htm

HTH
 
F

Ferman

I have written a java application and package it in the ajr file with
"Templates/" directory and its files. Later I have written a jnlp file. This
program run and first all list the file names in the "Templates/" directory
in the jar file. But the application didn't list the file names.

First application codes like this;

File f = new File(".\\Templates\\");
File files[] = f.listFiles();

Because this code didn't list the file names, I changed it like this;

URL vUrl =
ClassLoader.getSystemClassLoader().getResource("Templates/");
File f = new File(vUrl.getFile());
File files[] = f.listFiles();

But again it didn't list the file name.

Should I do for this ?

Thanks.
 
R

Roedy Green

URL vUrl = ClassLoader.getSystemClassLoader().getResource("Templates/");
File f = new File(vUrl.getFile());
File files[] = f.listFiles();

Though the entries in a zip are analogous to files in a dir, they are
not the same thing, though it would make sense to gradually merge the
notions.


See the Zip class and brothers.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top