java非递归方式实现遍历文件夹里的所有文件
LinkedList<File> dirList = new LinkedList<File>()
File file = new File(path)
if(file.exists()){
if(file.isDirectory()){
File[] files = file.listFiles()
for(File f : files){
if(f.isDirectory()){
dirList.add(f)
}else{
System.out.println(f.getAbsolutePath())
}
}
}
File temp = null
while(!dirList.isEmpty()){
temp = dirList.removeFirst()
if(temp.isDirectory()){
File [] fs = temp.listFiles()
for(File f : fs){
if(f.isDirectory()){
dirList.add(f)
}else{
System.out.println(f.getAbsolutePath())
}
}
}else{
System.out.println(temp.getAbsolutePath())
}
}
}