Java File Delete nio safeDeleteFile(final String fileName)

Here you can find the source of safeDeleteFile(final String fileName)

Description

safe Delete File

License

Apache License

Declaration

public static void safeDeleteFile(final String fileName) 

Method Source Code


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

import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    public static void safeDeleteFile(final String fileName) {
        final FileSystem fs = FileSystems.getDefault();
        final Path pdfFilePath = fs.getPath(fileName);

        try {/*from ww w.  j a va2 s.c o  m*/
            Files.delete(pdfFilePath);
        } catch (Exception ex) {
            // do nothing
        } finally {
            // we actually want to keep it open
            // it might be expensive to keep open/close
            // and sometimes this throws exceptions
            // fs.close();
        }
    }
}

Related

  1. forceDelete(File file)
  2. forceDelete(final File file)
  3. forceDeletion(File fileToDelete)
  4. recDeleteDirFile(File f)
  5. recursiveDelete(File parent)
  6. secureDelete(File file)