Answer the question
In order to leave comments, you need to log in
Why does it throw an exception when traversing a too deep directory?
FileSearch
import java.io.File;
import java.util.HashSet;
public class FileSearcher {
//Директория для поиска
private final File dir;
//Список папок в директории
private final HashSet<File> listDirectories;
private boolean findSwitch = true;
//Конструктор принимающий путь к директории
public FileSearcher(String dirPath) {
dir = new File(dirPath);
listDirectories = new HashSet<>();
//Получить первые папки для списка
for(File i : dir.listFiles()){
if(i.isDirectory()){
listDirectories.add(i);
}
}
}
public void dirFileWalk(){
for(File dirs : listDirectories){
findSwitch = false;
for(File i : dirs.listFiles()){
if(i.isDirectory() && !listDirectories.contains(i)){
listDirectories.add(i);
findSwitch = true;
}
}
}
}
public HashSet<File> start(){
while(findSwitch)
dirFileWalk();
return listDirectories;
}
}
public class Main {
public static void main(String[] args){
FileSearcher a = new FileSearcher
("c:/Users/Denis/Desktop/pages");
HashSet<File> dirs = a.start();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question