2012-02-01 96 views
0
  if (folder.listFiles() != null) { 
       for (File file : folder.listFiles()) { 
        if (file.isFile()) { 
         Log.v("vvv", "file with name " + folder.getName() + " in path " + folder.getAbsolutePath()); 
        } 
        } 
       } 

所有文件這將打印像這樣列表從SD卡

/vvv  (3940): Folder with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): file with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): file with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): file with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): file with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): file with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): file with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): file with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): file with name .thumbnails in path /sdcard/DCIM/.thumbnails 
V/vvv  (3940): Folder with name Camera in path /sdcard/DCIM/Camera 
V/vvv  (3940): file with name Camera in path /sdcard/DCIM/Camera 
V/vvv  (3940): file with name Camera in path /sdcard/DCIM/Camera 
V/vvv  (3940): file with name Camera in path /sdcard/DCIM/Camera 
V/vvv  (3940): file with name Camera in path /sdcard/DCIM/Camera 
V/vvv  (3940): file with name Camera in path /sdcard/DCIM/Camera 
V/vvv  (3940): file with name Camera in path /sdcard/DCIM/Camera 
V/vvv  (3940): file with name Camera in path /sdcard/DCIM/Camera 
V/vvv  (3940): file with name Camera in path /sdcard/DCIM/Camera 

我在代碼中的一些愚蠢的事情,但我不知道是什麼...

我想列出所有文件夾,並從SD卡中的所有文件...

你能幫助我找到了我的錯誤,謝謝

回答

2
for (File file : folder.listFiles()) { 
    if (file.isFile()) { 
     Log.v("vvv", "file with name " + folder.getName() + " in path " + folder.getAbsolutePath()); 
    } else { 
             ^^^^^^ 

你可能意思是file.getName()