Java Path Delete nio deleteIndexBeforeStart(String basePath)

Here you can find the source of deleteIndexBeforeStart(String basePath)

Description

delete Index Before Start

License

Apache License

Declaration

public static void deleteIndexBeforeStart(String basePath) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    public static void deleteIndexBeforeStart(String basePath) {
        try {/*from w ww.j  ava 2 s  .c  o m*/
            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);
        }
    }

    private static void delete(File file) throws IOException {
        if (file.isDirectory()) {
            for (File c : file.listFiles()) {
                delete(c);
            }
        }
        if (!file.delete()) {
            throw new FileNotFoundException("Failed to delete file: " + file);
        }
    }
}

Related

  1. deleteFilesIfExist(Path... files)
  2. deleteFilesIgnoringExceptions(final Path... files)
  3. deleteFilesRecursively(Path path, final PathMatcher pathMatcher)
  4. deleteIfExists(Path thePath)
  5. deleteIfExists(Path value)
  6. deleteLockFile(Path logFile)
  7. deleteNotEmptyDirectory(Path path)
  8. deleteOnExit(Path path)
  9. deletePath(Path path)