(J2ME) How to get a list of files / resources in my jar application

So, I am creating a mobile application using j2me and lwuit. In this application, the user will open the file.

My question is how to get the list of files in my jar application.

Example: inside the res folder there is:

File1.fl, File2.fl, File3.fl,

We can open a single file using the getResourceAsStream() function. But how do I get a list of file names inside a folder.

I came across FileConnection , but it seems that it is used to access files on the local phone.

In java, we can do this with the File class. Anyone can help me with these ... Thanks guys ..

+4
source share
1 answer

This works for applets, at least:

 ClassLoader cl = getClass().getClassLoader(); URL url = cl.getResource("META-INF/MANIFEST.MF"); /* just a random file that known to exist */ JarURLConnection conn = (JarURLConnection)url.openConnection(); JarFile jar = conn.getJarFile(); Enumeration e = jar.entries(); 

Then you need to go through the listing and select the appropriate items. Note that the entries will be the full path names inside the jar, and these directories may not be present as their own entries, but only as part of the path to the files contained inside.

+1
source

Source: https://habr.com/ru/post/1382807/


All Articles