Java Delete File or Directory deleteFileOrFolder(File fileOrFolder)

Here you can find the source of deleteFileOrFolder(File fileOrFolder)

Description

Delete the file or folder given in fileOrFolder.

License

Open Source License

Parameter

Parameter Description
fileOrFolder The file or folder to delete.

Declaration

public static void deleteFileOrFolder(File fileOrFolder) 

Method Source Code

//package com.java2s;
/*******************************************************************
 * Copyright (c) 2006-2013, Cloudsmith Inc.
 * The code, documentation and other materials contained herein
 * are the sole and exclusive property of Cloudsmith Inc. and may
 * not be disclosed, used, modified, copied or distributed without
 * prior written consent or license from Cloudsmith Inc.
 ******************************************************************/

import java.io.File;

public class Main {
    /**/*  w w w .  j av  a 2 s.  co  m*/
     * Delete the file or folder given in <code>fileOrFolder</code>. A folder
     * will be cleaned out (recursively) before it is deleted.
     * 
     * @param fileOrFolder
     *            The file or folder to delete.
     */
    public static void deleteFileOrFolder(File fileOrFolder) {
        File[] files = fileOrFolder.listFiles();
        if (files != null) {
            int idx = files.length;
            while (--idx >= 0)
                deleteFileOrFolder(files[idx]);
        }
        fileOrFolder.delete();
    }
}

Related

  1. deleteFileOrDirectory(File file)
  2. deleteFileOrDirectory(File fileOrDirectory)
  3. deleteFileOrDirectory(String fileName)
  4. deleteFileOrDirectoryRecursive(String dir)
  5. deleteFileOrDirOnExit(File filehandle)