Java Delete File or Directory deleteFileOrDirectory(File file)

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

Description

Delete a directory or file

License

Open Source License

Parameter

Parameter Description
file - the file or directory

Exception

Parameter Description
IOException an exception

Declaration

public static void deleteFileOrDirectory(File file) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 CA.  All rights reserved.
 *
 * This source file is licensed under the terms of the Eclipse Public License 1.0
 * For the full text of the EPL please see https://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

import java.io.File;

import java.io.IOException;

public class Main {
    /**//from   w  ww. j av a 2  s  .  c  o  m
     * Delete a directory or file 
     * 
     * @param file - the file or directory
     * @throws IOException
     */
    public static void deleteFileOrDirectory(File file) throws IOException {
        if (file.delete())
            System.out.println("Deleted : " + file.getAbsolutePath());
        else
            System.out.println("Failed to delete : " + file.getAbsolutePath());
    }
}

Related

  1. deleteFileOrDir(File file)
  2. deleteFileOrDir(File file)
  3. deleteFileOrDir(File filehandle)
  4. deleteFileOrDir(File instanceFileOrDir)
  5. deleteFileOrDirectory(File dir)
  6. deleteFileOrDirectory(File fileOrDirectory)
  7. deleteFileOrDirectory(String fileName)
  8. deleteFileOrDirectoryRecursive(String dir)
  9. deleteFileOrDirOnExit(File filehandle)