獲取系統全部文件集合

private Handler handler = new Handler(){
    @Override
public void handleMessage(Message msg) {
super.handleMessage(msg);

adapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1,list_s);
mListView.setAdapter(adapter);
}
};

final File dirFile = Environment.getRootDirectory();
new Thread(new Runnable() {
@Override
public void run() {
ShowFile(dirFile);
handler.sendEmptyMessage(0);
}
}).start();


private void ShowFile(File dirFile){    if(dirFile.exists()&&dirFile!=null){        if(dirFile.isDirectory()&&dirFile!=null&&dirFile.listFiles()!=null){            Log.i(TAG,"path is "+dirFile.getPath()+"\nlength = "+dirFile.length());            for (File file:dirFile.listFiles()) {                if(file.isDirectory()&&file!=null&&file.length()!=0){                    ShowFile(file);                }else{                    list_s.add(file.getPath());                }            }        }else{            list_s.add(dirFile.getPath());        }    }}
相關文章
相關標籤/搜索