Get filenames from a directory in Android

前端 未结 6 1873
日久生厌
日久生厌 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:30

    Try below code

    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File(sdCard, "yourpath");
    for (File f : dir.listFiles()) {
        if (f.isFile())
            String name = f.getName();
            // do whatever you want with filename
    }
    

提交回复
热议问题