Java Delete File Recursively deleteRecursively(File file)

Here you can find the source of deleteRecursively(File file)

Description

delete Recursively

License

Open Source License

Declaration

public static void deleteRecursively(File file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011, 2014 EclipseSource and others.
 * 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://from   w w w  .  j  a  va 2  s.  c om
 *    EclipseSource - initial API and implementation
 ******************************************************************************/

import java.io.File;

public class Main {
    public static void deleteRecursively(File file) {
        if (file.exists()) {
            File[] files = file.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    deleteRecursively(files[i]);
                }
            }
            boolean deleted = file.delete();
            if (!deleted) {
                throw new RuntimeException("Could not delete file or directory: " + file.getAbsolutePath());
            }
        }
    }
}

Related

  1. deleteRecursively(File file)
  2. deleteRecursively(File file)
  3. deleteRecursively(File file)
  4. deleteRecursively(File file)
  5. deleteRecursively(File file)
  6. deleteRecursively(File file)
  7. deleteRecursively(File file)
  8. deleteRecursively(File file)
  9. deleteRecursively(File file)