Java File Delete nio deleteFile(String fileName)

Here you can find the source of deleteFile(String fileName)

Description

Deletes the given file

License

LGPL

Parameter

Parameter Description
fileName The path for the file

Return

True: If the file was successfully deleted

Declaration

public static boolean deleteFile(String fileName) 

Method Source Code

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

import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    /**//www .  j  ava 2  s .c  o  m
     * Deletes the given file
     *
     * @param fileName
     *            The path for the file
     * @return True: If the file was successfully deleted
     */
    public static boolean deleteFile(String fileName) {
        Path p = Paths.get(fileName);

        try {
            return Files.deleteIfExists(p);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. deleteAll(File f)
  2. deleteAll(File file)
  3. deleteEntriesFromZip(File zipFile, List entriesToDelete)
  4. deleteFile(File f)
  5. deleteFile(File f)
  6. deleteFile(String filename)
  7. deleteFileCascade(String directory)
  8. deleteFileRescursive(File file)
  9. deleteFiles(File directory, String affix)