(J2ME) How to get list of files/resources inside my jar app

时光毁灭记忆、已成空白 提交于 2019-12-23 12:43:31

问题


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..


回答1:


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.



来源:https://stackoverflow.com/questions/8251669/j2me-how-to-get-list-of-files-resources-inside-my-jar-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!