Java Utililty Methods File Delete nio

List of utility methods to do File Delete nio

Description

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

Method

voidforceDelete(File file)
force Delete
if (file.isDirectory()) {
    deleteDirectory(file);
} else {
    final boolean filePresent = file.exists();
    if (!file.delete()) {
        if (!filePresent)
            throw new FileNotFoundException("File does not exist: " + file);
        final String message = "Unable to delete file: " + file;
...
voidforceDelete(File file)
Deletes a file.
if (file.isDirectory()) {
    deleteDirectory(file);
} else {
    Files.delete(file.toPath());
voidforceDelete(final File file)
Deletes a file.
if (file == null) {
    return;
if (file.isDirectory()) {
    deleteDirectory(file);
} else {
    final boolean filePresent = file.exists();
    if (!file.delete()) {
...
voidforceDeletion(File fileToDelete)
Forces the deletion of the specified file.
if (fileToDelete.exists() && !fileToDelete.canWrite()) {
    fileToDelete.setWritable(true);
try (Stream<Path> paths = Files.walk(fileToDelete.toPath())) {
    paths.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
voidrecDeleteDirFile(File f)
Deletes the file passed in.
if (f.isFile()) {
    Files.delete(f.toPath());
} else if (f.isDirectory()) {
    for (File file : f.listFiles()) {
        if (file.isDirectory()) {
            recDeleteDirFile(file);
        Files.delete(file.toPath());
...
booleanrecursiveDelete(File parent)
recursive Delete
if (parent.exists()) {
    if (parent.isDirectory()) {
        File[] files = parent.listFiles();
        for (int ifile = 0; ifile < files.length; ++ifile) {
            if (files[ifile].isDirectory()) {
                recursiveDelete(files[ifile]);
            if (files[ifile].exists()) {
...
voidsafeDeleteFile(final String fileName)
safe Delete File
final FileSystem fs = FileSystems.getDefault();
final Path pdfFilePath = fs.getPath(fileName);
try {
    Files.delete(pdfFilePath);
} catch (Exception ex) {
} finally {
voidsecureDelete(File file)
Securely deletes a file.
secureDelete(file, 1);