列出外部和内部存储文件

时间:2016-03-11 14:00:04

标签: android storage

我知道如何列出文件,但

getFilesDir()

Environment.getExternalStorageDirectory()

都提供了内部存储列表

请帮帮我

完整代码

内部

File dir = new File(getFilesDir().getAbsolutePath());

File[] list = dir.listFiles();
String[] name = new String[list.length];
for (int i = 0; i < name.length; i++) {
    name[i] = list[i].getName();
}

ListAdapter adapter = new FilesAdapter(this, android.R.layout.simple_list_item1, name);
ListView listView = (ListView) findViewById(R.id.internal_list);
listView.setAdapter(adapter);

外部

File sdcard = Environment.getExternalStorageDirectory();
File dir = new File(sdcard.getAbsolutePath());

File[] list = dir.listFiles();
String[] name = new String[list.length];
for (int i = 0; i < name.length; i++) {
    name[i] = list[i].getName();
}

ListAdapter adapter = new FilesAdapter(this, android.R.layout.simple_list_item1, name);
ListView listView = (ListView) findViewById(R.id.internal_list);
listView.setAdapter(adapter);

由于

0 个答案:

没有答案