//Delete a Directory
//DelDir.java
//yuyang
import java.io.*;
import java.util.*;
public class DelDir
{
private static void deletefile(File delpath) throws FileNotFoundException,IOException
{
File[] filelist=delpath.listFiles();
if (filelist.length!=0)
{
for (int i=0;i<filelist.length;i++)
{
if (filelist[i].isDirectory())
deletefile(filelist[i]);
else
filelist[i].delete();
}
delpath.delete();
}
else
delpath.delete();
}
public static void main(String[] args)
{
File file1=new File("e:\\test");
try
{
deletefile(file1);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
本文地址:http://com.8s8s.com/it/it15562.htm