del File tree - Java java.nio.file

Java examples for java.nio.file:Path

Description

del File tree

Demo Code


import java.io.*;
import java.net.*;
import java.util.*;
import java.util.zip.*;
import org.apache.log4j.*;

public class Main{
    public static void deltree(File file) throws IOException {
        //logger.info("file = " + file);
        if (!file.exists())
            return;
        if (file.isDirectory()) {
            String[] children = file.list();
            for (int i = 0; i < children.length; i++)
                deltree(new File(file, children[i]));
            file.delete();/*from  w  w w  . ja  v  a2 s  . co m*/
        } else if (file.isFile())
            file.delete();
    }
}

Related Tutorials