Java Delete Directory deleteFiles(final File... files)

Here you can find the source of deleteFiles(final File... files)

Description

Delete a list of files, and write a warning message if one could not be deleted.

License

Open Source License

Parameter

Parameter Description
files Files to be deleted.

Declaration

public static void deleteFiles(final File... files) 

Method Source Code


//package com.java2s;
/*//  ww  w  . ja v  a  2 s  . co  m
 * The MIT License
 *
 * Copyright (c) 2009 The Broad Institute
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.io.*;

public class Main {
    /**
     * Delete a list of files, and write a warning message if one could not be deleted.
     * @param files Files to be deleted.
     */
    public static void deleteFiles(final File... files) {
        for (final File f : files) {
            if (!f.delete()) {
                System.err.println("Could not delete file " + f);
            }
        }
    }

    public static void deleteFiles(final Iterable<File> files) {
        for (final File f : files) {
            if (!f.delete()) {
                System.err.println("Could not delete file " + f);
            }
        }
    }
}

Related

  1. deleteFiles(File[] intermediateFiles)
  2. deleteFiles(FileFilter filter)
  3. deleteFiles(final ArrayList files)
  4. deleteFiles(final File directory, final String regexPattern)
  5. deleteFiles(final File file)
  6. deleteFiles(List files)
  7. deleteFiles(String dir)
  8. deleteFiles(String dir, String... files)
  9. deleteFiles(String directory, FileFilter filter, boolean recursive)