From 118bb3e5c95e65544745b9d8a0039e90abf360c4 Mon Sep 17 00:00:00 2001 From: "Task-1.1" Date: Sun, 27 Dec 2020 09:38:14 +0500 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=208.?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/example/task02/Task02Main.java | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) 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; } }