(J2ME)如何获取我的jar应用程序中的文件/资源​​列表 [英] (J2ME) How to get list of files/resources inside my jar app

查看:128
本文介绍了(J2ME)如何获取我的jar应用程序中的文件/资源​​列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在用j2me和lwuit创建一个移动应用程序。
在该应用程序中,用户将打开一个文件。



我的问题是如何获取我的jar应用程序中的文件列表。



例如:在res文件夹中有:

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

我们可以使用 getResourceAsStream()函数打开一个文件。
但是如何得到文件夹中的文件名列表。



我遇到了 FileConnection 但它似乎是用来访问本地手机中的文件。



在java中,我们可以使用 File 谢谢你们。

解决方案

至少:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆