Java Delete File deleteFile(File file)

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

Description

delete File

License

Open Source License

Declaration

private static void deleteFile(File file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012, 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://ww w. j  a v  a 2s . co m
 *    EclipseSource - initial API and implementation
 ******************************************************************************/

import java.io.File;

public class Main {
    private static void deleteFile(File file) {
        if (!file.delete() && file.exists()) {
            throw new IllegalStateException("Could not delete: " + file.getPath());
        }
    }

    public static void delete(File file) {
        if (file.isDirectory()) {
            deleteChildren(file);
        }
        deleteFile(file);
    }

    private static void deleteChildren(File file) {
        for (File child : file.listFiles()) {
            delete(child);
        }
    }
}

Related

  1. deleteFile(File file)
  2. deleteFile(File file)
  3. deleteFile(File file)
  4. deleteFile(File file)
  5. deleteFile(File file)
  6. deleteFile(File file)
  7. deleteFile(File file)