Java Recursive Delete recursiveDelete(String fileName)

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

Description

recursive Delete

License

Open Source License

Declaration

public static boolean recursiveDelete(String fileName) 

Method Source Code


//package com.java2s;
/*//  w  ww .  ja  v  a 2s.c  o  m
 * This file is part of RskJ
 * Copyright (C) 2017 RSK Labs Ltd.
 * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;

public class Main {
    private static final Logger LOGGER = LoggerFactory.getLogger("file");

    public static boolean recursiveDelete(String fileName) {
        File file = new File(fileName);
        if (file.exists()) {
            //check if the file is a directory
            if (file.isDirectory() && (file.list()).length > 0) {
                for (String s : file.list()) {
                    //call deletion of file individually
                    recursiveDelete(fileName + System.getProperty("file.separator") + s);
                }
            }

            if (!file.setWritable(true)) {
                LOGGER.error("File {} is not writable", file);
            }

            boolean result = file.delete();
            return result;
        } else {
            return false;
        }
    }
}

Related

  1. recursiveDelete(final File fileOrDir)
  2. recursiveDelete(final File path)
  3. recursiveDelete(final File path, final boolean deleteParent)
  4. recursiveDelete(final File pFile)
  5. recursiveDelete(final File root, final File file)
  6. recursiveDelete(String p_path, boolean p_deletemetoo)
  7. recursiveDelete(String path)
  8. recursiveDeleteFile(File f)
  9. recursiveDeleteFile(File file)