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

Clean Directory 

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.cleanDirectory() API. It cleans the given directory without deleting it. It deletes all files and folder in it.

File Name  :  
com/bethecoder/tutorials/commons_io/tests/CleanDirectory.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.commons_io.tests;

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

import org.apache.commons.io.FileUtils;

public class CleanDirectory {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    File directory = new File("C:/Test2");
    
    //Deletes all files and folders in this directory.
    FileUtils.cleanDirectory(directory);

    System.out.println("Directory cleared successfully");
  }
}
   

It gives the following output,
Directory cleared successfully


                    Print

   



Books Recommendation

 
 
bl  br