Java Utililty Methods Path Delete nio

List of utility methods to do Path Delete nio

Description

The list of methods to do Path Delete nio are organized into topic(s).

Method

voiddeleteFile(Path path)
Deletes a file relative to the upload path
try {
    Files.delete(Paths.get(UPLOAD_FOLDER).resolve(path));
} catch (IOException ex) {
voiddeleteFile(Path path)
Deletes a file
try {
    Files.delete(path);
} catch (NoSuchFileException x) {
    System.err.format("%s: no such" + " file or directory%n", path);
} catch (DirectoryNotEmptyException x) {
    System.err.format("%s not empty%n", path);
} catch (IOException x) {
    System.err.println(x);
...
voiddeleteFile(String filePath)
Deletes a file if the file exists in the given filePath
Path path = Paths.get(filePath);
Files.deleteIfExists(path);
voiddeleteFile(String path)
delete File
Files.delete(new File(path).toPath());
voiddeleteFilesIfExist(Path... files)
Deletes all given Paths, if they exist.
deleteFilesIfExist(Arrays.asList(files));
voiddeleteFilesIgnoringExceptions(final Path... files)
Deletes all given files, suppressing all thrown IOException s.
deleteFilesIgnoringExceptions(Arrays.asList(files));
intdeleteFilesRecursively(Path path, final PathMatcher pathMatcher)
Deletes the files that match the PathMatcher.
final AtomicInteger counter = new AtomicInteger();
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
    @Override
    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        if (pathMatcher.matches(file)) {
            Files.delete(file);
            counter.incrementAndGet();
        return FileVisitResult.CONTINUE;
});
return counter.get();
voiddeleteIfExists(Path thePath)
delete If Exists
try {
    Files.walkFileTree(thePath, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.deleteIfExists(file);
            return FileVisitResult.CONTINUE;
        @Override
...
booleandeleteIfExists(Path value)
delete If Exists
return Files.deleteIfExists(value);
voiddeleteIndexBeforeStart(String basePath)
delete Index Before Start
try {
    Path path = Paths.get(basePath);
    boolean exists = Files.exists(path);
    boolean directory = Files.isDirectory(path);
    if (exists && directory) {
        File file = new File(basePath);
        delete(file);
} catch (IOException e) {
    System.out.println("Impossible to delete index path");
    System.exit(0);