java IO recursive delete commented
@@ -152,44 +152,33 @@ public class OFileUtils {
if (!rootFile.exists())
return;
- if (rootFile.isDirectory()){
- File[] subFiles = rootFile.listFiles();
- for (File subFile : subFiles){
- deleteRecursively(subFile);
- }
+ try {
+ Path rootPath = Paths.get(rootFile.getCanonicalPath());
+ Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.deleteIfExists(file);
+ return FileVisitResult.CONTINUE;
}
- rootFile.delete();
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ Files.deleteIfExists(dir);
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
-// try {
-// Path rootPath = Paths.get(rootFile.getCanonicalPath());
-// Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
-// @Override
-// public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-// Files.deleteIfExists(file);
-// return FileVisitResult.CONTINUE;
+// if (rootFile.isDirectory()){
+// File[] subFiles = rootFile.listFiles();
+// for (File subFile : subFiles){
+// deleteRecursively(subFile);
// }
-//
-// @Override
-// public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
-// Files.deleteIfExists(dir);
-// return FileVisitResult.CONTINUE;
-// }
-//
-// @Override
-// public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException
-// {
-// // try to delete the file anyway, even if its attributes
-// // could not be read, since delete-only access is
-// // theoretically possible
-// Files.delete(file);
-// return FileVisitResult.CONTINUE;
// }
//
-// });
-// } catch (IOException e) {
-// throw new IllegalStateException(e);
-// }
+// rootFile.delete();
}
public static void deleteFolderIfEmpty(final File dir) {
