Java Folder Delete nio deleteFile(String folderName, String fileName)

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

Description

delete File

License

Mozilla Public License

Declaration

public static boolean deleteFile(String folderName, String fileName) throws IOException 

Method Source Code

//package com.java2s;
/**//from  w  w  w .jav a 2s.  com
 * Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import java.io.IOException;

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

public class Main {
    public static boolean deleteFile(String folderName, String fileName) throws IOException {
        Path filePath = Paths.get(folderName, fileName);
        boolean deleted = Files.deleteIfExists(filePath);
        return deleted;
    }

    public static boolean deleteFile(String fileName) throws IOException {
        Path filePath = Paths.get(fileName);
        boolean deleted = Files.deleteIfExists(filePath);
        return deleted;
    }
}

Related

  1. delete(Path folder, List noDeleteFiles)
  2. deleteEmptyFolder(String... dirNames)
  3. deleteFolder(Path folder)
  4. deleteFolder(Path path)
  5. deleteFolderAndSubfolders(Path pathToFile)
  6. deleteRecursively(File folder)