獲取SD卡目錄文件

File sdFile = android.os.Environment.getExternalStorageDirectory();
        String rootPath = sdFile.getAbsolutePath() + File.separator; 
        List<String> items = new ArrayList<String>();
        final List<String> paths = new ArrayList<String>();
        File f = new File(filePath);
        File[] files = f.listFiles();
        if(rootPath.indexOf(filePath) == -1){
            items.add("返回上一級" + rootPath);
            paths.add(rootPath);
            items.add("主目錄");
            paths.add(f.getParent());
                   
        }
        for(int i =0;i<files.length; i++){
            File file = files[i];
            items.add(file.getName());
            paths.add(file.getPath());
        }
        ListView listView = (ListView)findViewById(R.id.lv);
        ArrayAdapter<String> fileList = new ArrayAdapter<String>(this, R.layout.file_row,items);
        listView.setAdapter(fileList);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章