fileOP

 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      }  

 

转载于:https://www.cnblogs.com/johnchain/p/3985351.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值