Java File Delete delete(File file)

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

Description

delete

License

Open Source License

Declaration

public static int delete(File file) 

Method Source Code

//package com.java2s;
/*//from  ww  w. j a va2s. c  o m
 * Copyright (c) 2007-2013, 2015 Eike Stepper (Berlin, Germany) 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:
 *    Eike Stepper - initial API and implementation
 *    Christian W. Damus (CEA LIST) - bug 418454
 */

import java.io.File;

public class Main {
    public static int delete(File file) {
        if (file == null) {
            return 0;
        }

        int deleted = 0;
        if (file.isDirectory()) {
            for (File child : file.listFiles()) {
                deleted += delete(child);
            }
        }

        if (file.delete()) {
            return deleted + 1;
        }

        file.deleteOnExit();
        return deleted;
    }
}

Related

  1. delete(File f)
  2. delete(File f, boolean recursive)
  3. delete(File file)
  4. delete(File file)
  5. delete(File file)
  6. delete(File file)
  7. delete(File file)
  8. delete(File file)
  9. delete(File file)