Get filenames from a directory in Android

前端 未结 6 1855
日久生厌
日久生厌 2021-01-17 15:43

I want to populate a spinner with the filenames of files found on the SD card with specific extensions. I can get it thus far to populate the spinner with the correct files,

6条回答
  •  深忆病人
    2021-01-17 16:29

    File sdCardRoot = Environment.getExternalStorageDirectory();
    File yourDir = new File(sdCardRoot, "path");
    for (File f : yourDir.listFiles()) {
        if (f.isFile())
            String name = f.getName();
            // Do your stuff
    }
    

    Have a look at Environment page for more info.

提交回复
热议问题