列出 sdcard 中的所有文件

发布于 2025-01-01 23:26:00 字数 1819 浏览 2 评论 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());
                    } 
                    }
                }

这会打印类似这样的内容

   /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卡中的所有文件夹和所有文件...

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

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

This prints something like this

   /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

I do some idiotic thing in the code, but I do not know what...

I want to list all the folders and all the files from the sdcard...

can you help me found my bug, Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埖埖迣鎅 2025-01-08 23:26:00
for (File file : folder.listFiles()) {
    if (file.isFile()) {
       Log.v("vvv", "file with name " + folder.getName() + " in path " + folder.getAbsolutePath());
    } else {
                                        ^^^^^^

您可能指的是file.getName()

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

You probably meant file.getName().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文