@Test public void deletePathRecursively() throws IOException { File tmpDir = mTestFolder.newFolder("dir"); File tmpDir1 = mTestFolder.newFolder("dir", "dir1"); File tmpDir2 = mTestFolder.newFolder("dir", "dir2"); File tmpFile1 = mTestFolder.newFile("dir/dir1/file1"); File tmpFile2 = mTestFolder.newFile("dir/dir1/file2"); File tmpFile3 = mTestFolder.newFile("dir/file3"); FileUtils.deletePathRecursively(tmpDir.getAbsolutePath()); assertFalse(tmpDir.exists()); assertFalse(tmpDir1.exists()); assertFalse(tmpDir2.exists()); assertFalse(tmpFile1.exists()); assertFalse(tmpFile2.exists()); assertFalse(tmpFile3.exists()); }
public static void deletePathRecursively(String path) throws IOException { if (!exists(path)) { return; } Path root = Paths.get(path); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); }
FileUtils { public static void deletePathRecursively(String path) throws IOException { if (!exists(path)) { return; } Path root = Paths.get(path); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); } }
FileUtils { public static void deletePathRecursively(String path) throws IOException { if (!exists(path)) { return; } Path root = Paths.get(path); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); } private  FileUtils(); }
FileUtils { public static void deletePathRecursively(String path) throws IOException { if (!exists(path)) { return; } Path root = Paths.get(path); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); } private  FileUtils(); static void changeLocalFileGroup(String path, String group); static void changeLocalFilePermission(String filePath, String perms); static void changeLocalFileToFullPermission(String filePath); static String getLocalFileOwner(String filePath); static String getLocalFileGroup(String filePath); static short getLocalFileMode(String filePath); static short translatePosixPermissionToMode(Set<PosixFilePermission> permission); static void changeLocalFileUser(String path, String user); static void setLocalDirStickyBit(String dir); static void createBlockPath(String path, String workerDataFolderPermissions); static void move(String srcPath, String dstPath); static void delete(String path); static void deletePathRecursively(String path); static boolean createStorageDirPath(String path, String workerDataFolderPermissions); static void createFile(String filePath); static void createDir(String path); static boolean exists(String path); static boolean isStorageDirAccessible(String path); }
FileUtils { public static void deletePathRecursively(String path) throws IOException { if (!exists(path)) { return; } Path root = Paths.get(path); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); } private  FileUtils(); static void changeLocalFileGroup(String path, String group); static void changeLocalFilePermission(String filePath, String perms); static void changeLocalFileToFullPermission(String filePath); static String getLocalFileOwner(String filePath); static String getLocalFileGroup(String filePath); static short getLocalFileMode(String filePath); static short translatePosixPermissionToMode(Set<PosixFilePermission> permission); static void changeLocalFileUser(String path, String user); static void setLocalDirStickyBit(String dir); static void createBlockPath(String path, String workerDataFolderPermissions); static void move(String srcPath, String dstPath); static void delete(String path); static void deletePathRecursively(String path); static boolean createStorageDirPath(String path, String workerDataFolderPermissions); static void createFile(String filePath); static void createDir(String path); static boolean exists(String path); static boolean isStorageDirAccessible(String path);  }