I have some folders with HTML files in the \"assets\" folder in my Android project. I need to show these HTML files from assets\' sub-folders in a list. I already wrote some
i think that this is best that check file is dir or not, altarnative try,catch!
public static List listAssetFiles(Context c,String rootPath) {
List files =new ArrayList<>();
try {
String [] Paths = c.getAssets().list(rootPath);
if (Paths.length > 0) {
// This is a folder
for (String file : Paths) {
String path = rootPath + "/" + file;
if (new File(path).isDirectory())
files.addAll(listAssetFiles(c,path));
else files.add(path);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return files;
}