【问题标题】:How do I access a "child" folder under a file?如何访问文件下的“子”文件夹?
【发布时间】:2019-11-12 21:38:16
【问题描述】:

我需要访问下载文件夹内的文件夹内的所有文件。

我可以像Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) 这样在下载文件夹中获取文件,然后返回File

除了文件夹mCustomFolder,我如何获得相同的结果?

【问题讨论】:

  • 您没有说明如何访问该下载文件夹中的所有文件。
  • 我相信这会有所帮助stackoverflow.com/a/9531063/764624
  • How do I access a “child” folder under a file? 你的意思是How do I access a “child” folder under a folder?

标签: android storage android-external-storage android-storage


【解决方案1】:

我猜应该很简单。试试这个。

File file = new File(Environment.getExternalStorageDirectory().getPath()+"/someFolder");

for(File f : files){
   //access your all files and folders here inside the given folder

}

详细了解here,了解如何访问外部存储。

【讨论】:

    【解决方案2】:

    我会这样做:

    File subDir = new File(
        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
        "/mCustomFolder/");
    File[] files = subDir.listFiles();
    for (File f : files) {
        // f is your file
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-02
      • 2013-02-03
      • 2014-03-31
      • 1970-01-01
      • 2020-04-04
      • 2018-11-16
      相关资源
      最近更新 更多