zoukankan      html  css  js  c++  java
  • 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      }  
  • 相关阅读:
    课程作业06-汇总整理
    课程作业04-汇总整理
    课程作业04-字串加密解密
    课程作业03-你已经创建了多少个对象?
    课程作业03-汇总整理
    课程作业02-汇总整理
    02-实验性问题总结归纳
    猜数字游戏
    RandomStr实验报告(验证码实验)
    个人总结
  • 原文地址:https://www.cnblogs.com/johnchain/p/3985351.html
Copyright © 2011-2022 走看看