JAVA ANDROID - 获得一个文件夹中的文件列表文件列表、文件、夹中、JAVA

2023-09-08 09:27:49 作者:小女子只卖身不卖艺

我开发必须显示在GridView型动物的文件夹中的影像上的应用,但我不知道我需要做的让与是一个文件夹内的绘制的文件名列表。

I'm developing a application that must display images of differents folders in a gridview, but i don't know what i need to do for get a list with the name of files that are inside a folder in "drawable".

请帮我

感谢您的时间

推荐答案

这种方法会给你包含目录的文件夹,并分文件夹列表列表:

this method will give you a list containing a list of dir folders and also sub folders:

public void listf(String directoryName, ArrayList<File> files) {
File directory = new File(directoryName);

// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
    if (file.isFile()) {
        files.add(file);
    } else if (file.isDirectory()) {
        listf(file.getAbsolutePath(), files);
    }
}
}
 
精彩推荐
图片推荐