0
재귀없이 파일 트리/디렉토리를 탐색하고 Java를 사용하여 스택을 탐색하는 방법을 참조하십시오.재귀없이 스택을 사용하여 파일 트리를 탐색하십시오.
public void traverse(Path path)
throws IOException
{
Stack<Stream<Path>> st = new Stack<>();
st.add(Files.list(path));
for(Iterator<Path> it = st.peek().iterator(); it.hasNext();)
{
Path temp = it.next();
final BasicFileAttributes fa = Files.readAttributes(temp, BasicFileAttributes.class);
if(fa.isDirectory())
{
//list all the directory contents
st.push(Files.list(temp));
}
else if(fa.isRegularFile())
{
}
else if(fa.isSymbolicLink()) {} //symbolic link
else if(fa.isOther()) {} //other
else {}
}
}
고마워요!