(J2ME)如何获取我的jar应用程序中的文件/资源列表 [英] (J2ME) How to get list of files/resources inside my jar app
问题描述
在该应用程序中,用户将打开一个文件。
我的问题是如何获取我的jar应用程序中的文件列表。
例如:在res文件夹中有:
File1.fl,
File2.fl,
File3.fl,
我们可以使用 getResourceAsStream()
函数打开一个文件。
但是如何得到文件夹中的文件名列表。
我遇到了 FileConnection
但它似乎是用来访问本地手机中的文件。
在java中,我们可以使用 File $ c
谢谢你们。
至少:
ClassLoader cl = getClass()。getClassLoader();
URL url = cl.getResource(META-INF / MANIFEST.MF); / *只是一个已知存在的随机文件* /
JarURLConnection conn =(JarURLConnection)url.openConnection();
JarFile jar = conn.getJarFile();
枚举e = jar.entries();
然后您必须通过枚举并选择适当的项目。请注意,这些条目将是jar内的完整路径名,并且这些目录可能不会作为它们自己的条目出现,而只是作为其中包含的文件的路径名的一部分。
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..
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.
这篇关于(J2ME)如何获取我的jar应用程序中的文件/资源列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!