List of utility methods to do Path Delete nio
void | deleteFile(Path path) Deletes a file relative to the upload path try { Files.delete(Paths.get(UPLOAD_FOLDER).resolve(path)); } catch (IOException ex) { |
void | deleteFile(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); ... |
void | deleteFile(String filePath) Deletes a file if the file exists in the given filePath Path path = Paths.get(filePath); Files.deleteIfExists(path); |
void | deleteFile(String path) delete File Files.delete(new File(path).toPath());
|
void | deleteFilesIfExist(Path... files) Deletes all given Paths, if they exist. deleteFilesIfExist(Arrays.asList(files)); |
void | deleteFilesIgnoringExceptions(final Path... files) Deletes all given files, suppressing all thrown IOException s. deleteFilesIgnoringExceptions(Arrays.asList(files)); |
int | deleteFilesRecursively(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(); |
void | deleteIfExists(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 ... |
boolean | deleteIfExists(Path value) delete If Exists return Files.deleteIfExists(value);
|
void | deleteIndexBeforeStart(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); |