org.lumongo.util.DeletingFileVisitor Maven / Gradle / Ivy
The newest version!
package org.lumongo.util;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
public class DeletingFileVisitor extends SimpleFileVisitor {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
if (attributes.isRegularFile()) {
Files.delete(file);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path directory, IOException ioe) throws IOException {
Files.delete(directory);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException ioe) throws IOException {
ioe.printStackTrace();
return FileVisitResult.CONTINUE;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy