获取文件名从Android的一个目录 [英] Get filenames from a directory in Android

查看:143
本文介绍了获取文件名从Android的一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写的Andr​​oid的应用程序,将填充微调与文件的SD卡带有特定扩展名上找到的文件名。我可以得到它迄今填充用正确的文件的微调,但路径显示为好。谁能告诉我怎么去一个特定的文件,只需在文件名中的Andr​​oid SD卡上的目录?

感谢您

解决方案

 文件sdCardRoot = Environment.getExternalStorageDirectory();
文件yourDir =新的文件(sdCardRoot,路径);
对于(文件F:yourDir.listFiles()){
    如果(f.isFile())
        字符串名称= f.getName();
        //做你的东西
}
 

看一看 环境 页了解更多信息。

I am trying to write an app in Android that will populate a spinner with the filenames of files found on the SD card with specific extensions. I can get it thus far to populate the spinner with the correct files, but the path is shown as well. Can anyone PLEASE tell me how to get ONLY the filename of a specific file in a directory on the SD card in Android?

Thank you

解决方案

File sdCardRoot = Environment.getExternalStorageDirectory();
File yourDir = new File(sdCardRoot, "path");
for (File f : yourDir.listFiles()) {
    if (f.isFile())
        String name = f.getName();
        // Do your stuff
}

Have a look at Environment page for more info.

这篇关于获取文件名从Android的一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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