0

我想扫描特定文件夹中的所有文件名,以将它们保存到数组中。

但是我怎样才能访问 sd 卡来做到这一点呢?

帮助会很棒(io / environment???)

4

2 回答 2

1

Environment.getExternalStorageDirectory() will link you to the SD card if one is inserted in the phone. Otherwise it just links you to your phone storage. Here's a link to more information on Environment http://developer.android.com/reference/android/os/Environment.html.

File file = new File(Environment.getExternalStorageDirectory()+"/folder/");
File[] files = file.listFiles();
String[] fileNames = new String[files.length];
for(int i = 0; i < files.length; i++) 
    fileNames[i] = files[i].getName();
于 2013-08-08T23:16:08.173 回答
0

您可以使用以下代码:

String filesDirectory = Environment.getExternalStorageDirectory().getAbsolutePath()+"/YOUR_SPECIFIC_FOLDER/"
File fileList = new FilefilesDirectory 
if (fileList != null)
{
File[] filenames = fileList.listFiles();
//Loop through each file and get the file name
String fileNamesArray[] = new String[filenames.length]; 
int i=0;
for (File tempFile : filenames)
    {
        fileNamesArray[i] = tempFile.getName();
        i++;
    }
}
于 2013-08-08T23:22:37.023 回答