Java – (J2ME) how to get the file / resource list in my jar application

So I'm using J2ME and lwuit to create a mobile application

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

For example, in the res folder:

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

We can use the getresourceasstream () function to open a file But how to get a list of file names in a folder

I encountered fileconnection, but it seems to be used to access files in my local phone

In Java, we can use the file class to do this Anyone can help me with these... Thank you

Solution

This applies to 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();

You must then complete the enumeration and select the appropriate item Please note that the entry will be the full pathname in the jar, and the directory may not appear as its own entry, but only as part of the pathname of the files it contains

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>