diff --git a/08-java-io2/task02/src/com/example/task02/Task02Main.java b/08-java-io2/task02/src/com/example/task02/Task02Main.java index 1c53b3533..242c2ebb4 100644 --- a/08-java-io2/task02/src/com/example/task02/Task02Main.java +++ b/08-java-io2/task02/src/com/example/task02/Task02Main.java @@ -2,22 +2,36 @@ import java.io.IOException; import java.nio.file.Path; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; import java.util.List; -public class Task02Main { - public static void main(String[] args) throws IOException, InterruptedException { - //здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат - // например вот так: - - /* - System.out.println(listFiles(Paths.get("task02/src/main/resources/"))); - */ - +public class Task02Main +{ + public static void main(String[] args) throws IOException, InterruptedException + { + for (Path path : listFiles(Paths.get("task02/src/main/resources/"))) + { + System.out.println(path.getFileName()); + } } - public static List listFiles(Path rootDir) throws IOException, InterruptedException { - // your implementation here + public static List listFiles(Path rootDir) throws IOException, InterruptedException + { + List files = new ArrayList(); + + FileVisitor fileVisitor = new SimpleFileVisitor() + { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) + { + files.add(file); + return FileVisitResult.CONTINUE; + } + }; - return null; + Files.walkFileTree(rootDir, fileVisitor); + return files; } }