【问题标题】:List all files from sdcard列出 sdcard 中的所有文件
【发布时间】:2012-02-01 10:57:47
【问题描述】:
            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

我在代码中做了一些愚蠢的事情,但我不知道是什么......

我想列出 sdcard 中的所有文件夹和所有文件...

你能帮我找到我的错误吗,谢谢

【问题讨论】:

    标签: android file-io sd-card


    【解决方案1】:
    for (File file : folder.listFiles()) {
        if (file.isFile()) {
           Log.v("vvv", "file with name " + folder.getName() + " in path " + folder.getAbsolutePath());
        } else {
                                            ^^^^^^
    

    你的意思可能是file.getName()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多