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

voidcleanUp(boolean isDeleteOriginalFiles, Path[] filesToZip)
clean Up
if (isDeleteOriginalFiles) {
    for (Path fileToZip : filesToZip) {
        Files.deleteIfExists(fileToZip);
voidclearAndDeleteDirecotry(Path path)
clear And Delete Direcotry
clearDirectory(path);
path.toFile().delete();
FileChannelcreateDeleteOnExitFile(Path path)
create Delete On Exit File
Set<StandardOpenOption> options = new HashSet<>();
options.add(StandardOpenOption.CREATE);
options.add(StandardOpenOption.DELETE_ON_CLOSE);
options.add(StandardOpenOption.WRITE);
return FileSystems.getDefault().provider().newFileChannel(path, options);
voiddelete(@Nullable Path path)
delete
if (path == null || !exists(path)) {
    return;
if (isRegularFile(path)) {
    doDelete(path);
    return;
walkFileTree(path, new SimpleFileVisitor<Path>() {
...
voiddelete(final Path path)
delete
if (Files.exists(path)) {
    try {
        if (Files.isDirectory(path)) {
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
                stream.forEach((entry) -> delete(entry));
        Files.delete(path);
...
voiddelete(final String[] paths)
delete
for (final String path : paths) {
    delete(path);
voiddelete(Path path)
delete
if (!Files.exists(path)) {
    return;
if (Files.isRegularFile(path)) {
    Files.delete(path);
} else {
    Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
        @Override
...
voiddelete(Path path)
Deletes file/directory representing the path.
if (path.toFile().exists()) {
    try (Stream<Path> stream = Files.walk(path)) {
        stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
voiddelete(Path path)
Deletes the path from the file system.
if (path != null) {
    try {
        if (Files.exists(path)) {
            if (Files.isDirectory(path)) {
                Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                            throws IOException {
...
voiddelete(Path root)
Deletes the file, if it is a directory, deletes its content recursively.
if (Files.isDirectory(root)) {
    final DirectoryStream<Path> subPaths = Files.newDirectoryStream(root);
    for (Path path : subPaths) {
        delete(path);
    subPaths.close();
    Files.delete(root);
} else {
...