Reputation: 424
So, I am creating a mobile application using j2me and lwuit. In that application the user will open a file.
My question is how do I get list of files inside my jar application..
Ex : Inside a res folder there are :
File1.fl, File2.fl, File3.fl,
We can open a single file using getResourceAsStream()
function.
But how do I get the list of file names inside the folder.
I came across with FileConnection
but it seems that it is used to access files in the local phone.
In java we can do this using the File
class.. Anyone can help me with these...
Thanks guys..
Upvotes: 4
Views: 1478
Reputation: 12824
This works for applets, at least:
ClassLoader cl = getClass().getClassLoader();
URL url = cl.getResource("META-INF/MANIFEST.MF"); /* just a random file that's known to exist */
JarURLConnection conn = (JarURLConnection)url.openConnection();
JarFile jar = conn.getJarFile();
Enumeration e = jar.entries();
Then you have to go through the enumeration and select the appropriate items. Note that the entries will be full pathnames inside the jar, and that directories may not be present as their own entries, but only as part of the pathname of the files contained within.
Upvotes: 1