非递归方法枚举目录下所有文件(含子目录)
3非递归方法枚举目录下所有文件(含子目录)private void getFileList(String dirPath)
{
LinkedList<File> mDirList = new LinkedList<File>();
File dir = new File(dirPath);
mDirList.add(dir);
File files[] = null;
int count = 0;
String filePath = null;
File tmp = null;
while (!mDirList.isEmpty()) {
tmp = mDirList.removeFirst();
//handle files in one directory.
files = tmp.listFiles();
if (files == null)
continue;
for (int i = 0; i < files.length; i++)
{
if (files.isDirectory())
mDirList.add(files);
else
{
Log.d(TAG,files.getAbsolutePath() + " " + count);
count ++;
}
}
}
Log.d(TAG,"getFileList finish,file count: " + count);
}
页:
[1]