Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How to clean contents of a directory using Apache commons-io API in Java ?

Program to demonstrate how to clean contents of a directory using Apache commons-io API in Java.

package com.hubberspot.apache.commons.examples;

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

import org.apache.commons.io.FileUtils;

public class CleanDirectoryDemo {

    public static void main(String[] args) {

        // Create a File object and pass path of the directory
        // where files needs to be cleaned
        File file = new File("D:/files");

        // FileUtils class of org.apache.commons.io
        // has a method by name cleanDirectory() which takes in
        // the directory where files need to be 
        // cleaned.

        try {

            FileUtils.cleanDirectory(file);

        } catch (IOException e) {
            
            e.printStackTrace();
        }

    }

}



 
© 2021 Learn Java by Examples Template by Hubberspot