Java Path Remove nio removeFile(String path)

Here you can find the source of removeFile(String path)

Description

remove File

License

Apache License

Declaration

public static boolean removeFile(String path) 

Method Source Code


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

import java.io.File;

import java.nio.file.*;

public class Main {
    public static boolean removeFile(String path) {

        File fileToRemove = loadFile(path);

        return fileToRemove.delete();
    }//from   www.  j  av  a 2 s.c  om

    public static File loadFile(String path) {
        if (path == null) {
            path = "/";
        }

        File f = new File(path);
        if (f.exists()) {
            return f.getAbsoluteFile();
        }

        if (!path.startsWith("/")) {
            path = "/" + path;
        }

        return new File(Paths.get("").toAbsolutePath().toString() + path.trim());
    }
}

Related

  1. removeDirectory(Path directory)
  2. removeDirectory(String pathToDir)
  3. removeDirectoryIfItIsEmpty(Path directoryToRemove)
  4. removeDriveLetter(Path path)
  5. removeFile(final String removePath)
  6. removeFile(String workspacePath)
  7. removeLine(String path, String line, boolean commentAware)
  8. removeRecursive(Path path)
  9. removeRecursive(Path path)