if (folder.listFiles() != null) {
for (File file : folder.listFiles()) {
if (file.isFile()) {
Log.v("vvv", "file with name " + folder.getName() + " in path " + folder.getAbsolutePath());
}
}
}
打印出类似这样的内容
/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卡中的所有文件夹和所有文件......
你可以帮我找到我的错误,谢谢答案 0 :(得分:2)
for (File file : folder.listFiles()) {
if (file.isFile()) {
Log.v("vvv", "file with name " + folder.getName() + " in path " + folder.getAbsolutePath());
} else {
^^^^^^
你可能意味着file.getName()
。