@Test void deleteRecursivelyShouldDeleteEverything() throws Exception { Path directory = Files.createTempDirectory(this.getClass().getSimpleName()); Path testData = directory.resolve("test_data"); Files.createFile(testData); Path testDir = directory.resolve("test_dir"); Files.createDirectory(testDir); Path testData2 = testDir.resolve("test_data"); Files.createFile(testData2); assertTrue(Files.exists(directory)); assertTrue(Files.exists(testData)); assertTrue(Files.exists(testDir)); assertTrue(Files.exists(testData2)); deleteRecursively(directory); assertFalse(Files.exists(directory)); assertFalse(Files.exists(testData)); assertFalse(Files.exists(testDir)); assertFalse(Files.exists(testData2)); }
public static void deleteRecursively(Path directory) throws IOException { checkNotNull(directory); walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { delete(dir); return FileVisitResult.CONTINUE; } }); }
Files { public static void deleteRecursively(Path directory) throws IOException { checkNotNull(directory); walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { delete(dir); return FileVisitResult.CONTINUE; } }); } }
Files { public static void deleteRecursively(Path directory) throws IOException { checkNotNull(directory); walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { delete(dir); return FileVisitResult.CONTINUE; } }); } private  Files(); }
Files { public static void deleteRecursively(Path directory) throws IOException { checkNotNull(directory); walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { delete(dir); return FileVisitResult.CONTINUE; } }); } private  Files(); static boolean createFileIfMissing(Path path, FileAttribute<?>... attrs); static void deleteRecursively(Path directory); static Path copyResource(String resourceName, Path destination, OpenOption... options); static long copyResource(String resourceName, OutputStream out); static void atomicReplace(Path path, byte[] bytes); static void atomicReplace(Path path, IOConsumer<Writer> fn); static void atomicReplace(Path path, Charset charset, IOConsumer<Writer> fn); }
Files { public static void deleteRecursively(Path directory) throws IOException { checkNotNull(directory); walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { delete(dir); return FileVisitResult.CONTINUE; } }); } private  Files(); static boolean createFileIfMissing(Path path, FileAttribute<?>... attrs); static void deleteRecursively(Path directory); static Path copyResource(String resourceName, Path destination, OpenOption... options); static long copyResource(String resourceName, OutputStream out); static void atomicReplace(Path path, byte[] bytes); static void atomicReplace(Path path, IOConsumer<Writer> fn); static void atomicReplace(Path path, Charset charset, IOConsumer<Writer> fn);  }