Java Path Delete nio deleteFile(Path path)

Here you can find the source of deleteFile(Path path)

Description

Deletes a file

License

Apache License

Parameter

Parameter Description
path - The file path

Declaration

public static void deleteFile(Path path) 

Method Source Code


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

import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;

public class Main {
    /**/*from  w ww .  j  a va  2  s. co  m*/
     * Deletes a file
     * @param path - The file path
     */
    public static void deleteFile(Path path) {
        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) {
            // File permission problems are caught here.
            System.err.println(x);
        }
    }
}

Related

  1. deleteEmptyDirsUpTo(Path from, Path to)
  2. deleteEmptyParentDirs(Path pkgDirPath, Path repoPath)
  3. deleteFile(Path p)
  4. deleteFile(Path path)
  5. deleteFile(Path path)
  6. deleteFile(String filePath)
  7. deleteFile(String path)
  8. deleteFilesIfExist(Path... files)
  9. deleteFilesIgnoringExceptions(final Path... files)