Android的,怎么能我得到一个文件夹中的所有文件的清单? [英] Android, how do can I get a list of all files in a folder?

查看:168
本文介绍了Android的,怎么能我得到一个文件夹中的所有文件的清单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的名称(字符串)资源中的所有文件/生/

I need the name (String) of all files in res/raw/

我想:

File f = new File("/"); 
String[] someFiles = f.list();

它看起来像根目录是Android模拟器的根......而不是我的电脑的根目录。这使得足够的理智,但并没有真正帮助我找出原始文件夹存在。

It looks like the root directory is the root of the android emulator...and not my computers root directory. That makes enough sense, but doesn't really help me find out where the raw folder exists.

谢谢!

更新:感谢所有伟大的答复。看来,其中的一些工作,但只让我半路上。或许更详细的说明,将有助于...

我想在原始文件夹中的所有MP3文件,所以我可以得到所有的名字,然后将它们添加到URI以下列方式播放一个随机的MP3 ...

I want to get all the mp3 files in the raw folder so I can get all the names, then add them to a URI to play a random MP3 in the following way...

String uriStr = "android.resource://"+ "com.example.phone"+ "/" + "raw/dennis";
Uri uri = Uri.parse(uriStr);
singletonMediaPlayer = MediaPlayer.create(c, uri);

当我把dennis.mp3注入资产的文件夹,但它显示为预期的...但是,使用上述code,我无法访问MP3了......除非有什么沿行:

When I put "dennis.mp3" into the assets folder, it does show up as expected...however, using the above code, I can't access that MP3 anymore...unless there is something along the line of:

String uriStr = "android.assets://"+ "com.example.phone"+ "/" + "dennis";
Uri uri = Uri.parse(uriStr);

再次感谢您的帮助的答案迄今。

Thanks again for the helpful answers thus far.

推荐答案

要列出您的原始资产,这基本上是与剥离扩展文件名的所有的名字,你可以这样做:

To list all the names of your raw assets, which are basically the filenames with the extensions stripped off, you can do this:

public void listRaw(){
    Field[] fields=R.raw.class.getFields();
    for(int count=0; count < fields.length; count++){
        Log.i("Raw Asset: ", fields[count].getName());
    }
}

由于实际文件不只是坐在一旦他们手机上的文件系统,这个名字是无关紧要的,你需要把它们分配给该资源名称整数。在上面的例子中,你可以得到这个整数是这样的:

Since the actual files aren't just sitting on the filesystem once they're on the phone, the name is irrelevant, and you'll need to refer to them by the integer assigned to that resource name. In the above example, you could get this integer thus:

int resourceID=fields[count].getInt(fields[count]);

这是相同的INT,你会参考R.raw.whateveryounamedtheresource获得

This is the same int which you'd get by referring to R.raw.whateveryounamedtheresource

这篇关于Android的,怎么能我得到一个文件夹中的所有文件的清单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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