Iterate through a specified directory in Android

烂漫一生 提交于 2020-02-19 09:44:12

问题


i am trying to develop a security application on Android and i want to iterate through the filenames of a specific directory so that i can compare the hash value of each file in the directory.

I have already found out how to do the hashing but for the iterating part i am confused on how it works.


回答1:


You mean you want to traverse a directory recursively?

Something like this:

public void traverse (File dir) {
    if (dir.exists()) {
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; ++i) {
            File file = files[i];
            if (file.isDirectory()) {
                traverse(file);
            } else {
                // do something here with the file
            }
        }
    }
} 


来源:https://stackoverflow.com/questions/12310577/iterate-through-a-specified-directory-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!