显示SD卡里的文件列表

读取SD卡文件信息,添加到ListView中显示出来:

 

ListView取得SD文件信息的代码:

  1. List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();        
  2.         String sDStateString = Environment.getExternalStorageState();  
  3.         if (sDStateString.equals(Environment.MEDIA_MOUNTED)) {  
  4.             try {  
  5.                 File SDFile = Environment.getExternalStorageDirectory();  
  6.                 File sdPath = new File(SDFile.getAbsolutePath());  
  7.                 if (sdPath.listFiles().length > 0) {  
  8.                     for (File file : sdPath.listFiles()) {  
  9.                         Map<String, Object> map = new HashMap<String, Object>();  
  10.                         map.put("text_content", file.getName());        //get filename  
  11.                         list.add(map);  
  12.                     }  
  13.                 }                 
  14.             } catch (Exception e) {  
  15.                 //  
  16.             }             
  17.         }         
  18.         return list; 
posted @ 2013-03-24 21:25  点点爱梦  阅读(82)  评论(0编辑  收藏  举报