遍历Android的指定目录 [英] Iterate through a specified directory in Android
本文介绍了遍历Android的指定目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图开发在Android安全应用程序,我想遍历一个特定目录的文件名,这样我可以比较目录中的每个文件的哈希值。
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.
推荐答案
你的意思是你想递归遍历目录?
You mean you want to traverse a directory recursively?
事情是这样的:
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
}
}
}
}
这篇关于遍历Android的指定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文