import java.io.File;
import java.io.IOException;
public class Delete {
/**
* @param args
*/
public void del(String filepath,int k) throws IOException {
File f = new File(filepath);
if (f.exists() && f.isDirectory())
{
if (f.listFiles().length == 0)//目錄下沒有東西
{
f.delete();
}
else
{
File delFile[] = f.listFiles();
int length = f.listFiles().length;
k++;
for (int j = 0; j < length; j++)
{
if (delFile[j].isDirectory())
{
System.out.println("k is :"+k);
del(delFile[j].getAbsolutePath(),k);
}
delFile[j].delete();
}
}
del(filepath,k);
}
}
public static void main(String[] args) {
String filepath = "C://fileserver//root folder//1//2";
Delete delete = new Delete();
int i = 0;
try
{
delete.del(filepath,i);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}