tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons IO > Basic > Force Delete

Force Delete 

Apache Commons IO is a java library with simple IO utilities and filters. This requires the library commons-io-2.1.jar to be in classpath. The following example shows using FileUtils.forceDelete() API. It deletes the given file or directory recursively. Throws IOException if the file or directory cannot be deleted.

File Name  :  
com/bethecoder/tutorials/commons_io/tests/ForceDelete.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_io.tests;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

public class ForceDelete {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    File file = new File("C:/Test.java");
    File directory = new File("C:/Test2");
    
    //Deletes this file or directory
    FileUtils.forceDelete(file);
    FileUtils.forceDelete(directory);
    System.out.println("Deleted successfully");
  }
}
   

It gives the following output,
Deleted successfully



 
  


  
bl  br