Enumerating a jar file

I

Ike

If I have an applet, with a path in it, say, GG.icons , and I want to
enumerate through each filename in GG.icons, EXCEPT that GG.icons is in the
same jar as my applet iteslf which is trying to enumerate through it....how
in the wild, wild world-o-sports can I do that? Does anyone have any idea?
Thanks, Ike
 
I

Ike

Yes, but thats not what I need to know - rather, I need to know how I can
iterate through a "directory" within the jar file that this applet resides
in. -Ike

Tony Morris said:
You load it as a resource.
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#getResource(java.lang.String)

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)


Ike said:
If I have an applet, with a path in it, say, GG.icons , and I want to
enumerate through each filename in GG.icons, EXCEPT that GG.icons is in the
same jar as my applet iteslf which is trying to enumerate through it....how
in the wild, wild world-o-sports can I do that? Does anyone have any idea?
Thanks, Ike
 
T

Tony Morris

Since your requirements seem to be somewhat contradictory, perhaps I can
suggest looking at JarInputStream ? Otherwise, I'm completely baffled as to
what you are trying to achieve.

Requires clarification:

"If I have an applet, with a path in it, say, GG.icons "
Applets don't have paths in them. Perhaps the JAR contains an applet as well
as other things ?
GC.icons is a file (or directory) within the JAR ?

"enumerate through each filename in GG.icons"
Should I assume that GC.icons is a directory and you want each filename in
that directory ?

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)


Ike said:
Yes, but thats not what I need to know - rather, I need to know how I can
iterate through a "directory" within the jar file that this applet resides
in. -Ike

Tony Morris said:
You load it as a resource.
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#getResource(java.lang.String)
--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)


Ike said:
If I have an applet, with a path in it, say, GG.icons , and I want to
enumerate through each filename in GG.icons, EXCEPT that GG.icons is
in
the
same jar as my applet iteslf which is trying to enumerate through it....how
in the wild, wild world-o-sports can I do that? Does anyone have any idea?
Thanks, Ike
 
I

Ike

"enumerate through each filename in GG.icons"
Should I assume that GC.icons is a directory and you want each filename in
that directory ?


Yes. This is what I am trying to do. Thanks Tony, Ike
 
T

Tony Morris

In that case,
You will want to load the JAR as a stream and enumerate each entry.
Following is code that I haven't tested, but you should get the general idea
(and perhaps reveal a better method after searching API docs.):

// http://java.sun.com/j2se/1.4.2/docs/api/java/util/jar/JarInputStream.html
JarInputStream in = new
JarInputStream(getClass().getResourceAsStream("GC.icons"));

// http://java.sun.com/j2se/1.4.2/docs/api/java/util/jar/JarEntry.html
JarEntry je;

while((je = in.getNextEntry()) != null)
{
//
http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/ZipEntry.html#isDirectory()
if(je.isDirectory())
{
System.out.println("Recursing down: " + je.getName());
// recursive call
}

System.out.println('\t' + je.getName());
}

// GOOD LUCK !

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 
A

Andrew Thompson

| If I have an applet, with a path in it, say, GG.icons , and I
want to
| enumerate through each filename in GG.icons,

JarFile.entries()
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top