java delete the directory

import java.io.*;
public class Practice_3 {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        File dir = new File("c:\\practice");
        removeDir(dir);
    }
    public static void sop(Object obj)
    {
        System.out.println(obj);
    }
    public static void removeDir(File dir)
    {
        File[] files = dir.listFiles();
        
        for( Int X = 0; X <files.length; X ++ ) 
        { 
            IF (Files [X] .isDirectory ()) // && can avoid the hidden files File [X] .isHidden ();! 
            { 
                RemoveDir (Files [X]); 
            } the else 
            { 
                System.out.println (Files [X] .toString () + "..... ::" + Files [X] .Delete ()); 
            } 
        } 
        SOP (the dir + " :: dir ..... "+ dir.delete ()); 
    } 
} 
/ * list files in the specified directory or a file folder that contains the contents of subdirectories. 
 * List all content that is in the specified directory 
 * directory because the directory there, so we use the same method, their calls itself, this method is called: Recursive 
 * Recursive Attention: 
 * 1, qualification.
 * 2, pay attention to the number of times recursive, try to avoid content overflow. 
 * 
 * * /
 

 

Guess you like

Origin www.cnblogs.com/zxl1010/p/11584431.html