Java Delete Directory deleteFiles(File directory)

Here you can find the source of deleteFiles(File directory)

Description

delete Files

License

Open Source License

Declaration

private static void deleteFiles(File directory) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 SAP and others./*from w w  w  .  ja va 2 s  .com*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * SAP - initial API and implementation
 *******************************************************************************/

import java.io.File;

public class Main {
    private static void deleteFiles(File directory) {
        if (directory != null) {
            for (File file : directory.listFiles()) {
                if (file.isDirectory()) {
                    deleteDirectory(file);
                }
                if (!file.delete()) {
                    file.deleteOnExit();
                }
            }
        }
    }

    public static void deleteDirectory(File directory) {
        if (directory != null) {
            deleteFiles(directory);
            directory.delete();
        }
    }
}

Related

  1. deleteDirectoryContents(File directory)
  2. deleteDirectoryContents(final File dir)
  3. deleteDirectoryContents(final File dir, int deleteDirLevel, int level)
  4. deleteFiles(File dir)
  5. deleteFiles(File dir)
  6. deleteFiles(File directory)
  7. deleteFiles(File directory)
  8. deleteFiles(File directory, String prefix)
  9. deleteFiles(File docFolder)