1 public void getFileDir(String filePath) {
2 try{
3 this.tv.setText("当前路径:"+filePath);// 设置当前所在路径
4 items = new ArrayList<String>();
5 paths = new ArrayList<String>();
6 File f = new File(filePath);
7 File[] files = f.listFiles();// 列出所有文件
8 // 如果不是根目录,则列出返回根目录和上一目录选项
9 if (!filePath.equals(rootPath)) {
10 items.add("返回根目录");
11 paths.add(rootPath);
12 items.add("返回上一层目录");
13 paths.add(f.getParent());
14 }
15 // 将所有文件存入list中
16 if(files != null){
17 Log.d("johnchain", "file not null");
18 int count = files.length;// 文件个数
19 for (int i = 0; i < count; i++) {
20 File file = files[i];
21 items.add(file.getName());
22 paths.add(file.getPath());
23 Log.d("johnchain", "add file " + file.getName());
24 Log.d("johnchain", "add path " + file.getPath());
25 }
26 }else{
27 Log.d("johnchain", "file null");
28 }
29 // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
30 // this.setListAdapter(adapter);
31 }catch(Exception ex){
32 ex.printStackTrace();
33 }
34
35 }