首页 > 其他 > 详细

fileOP

时间:2015-02-28 15:59:36      阅读:220      评论:0      收藏:0      [点我收藏+]
 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      }  

 

fileOP

原文:http://www.cnblogs.com/johnchain/p/3985351.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!