- import java.io.*;
- class RemoveDir
- {
- public static void main(String[] args)
- {
- File dir=new File("F:\\test.txt");
- removeDir(dir);
- }
- public static void removeDir(File dir)
- {
- File[] files = dir.listFiles();
- for (int x=0;x<files.length ;x++ )
- {
- if (files[x].isDirectory())
- removeDir(files[x]);
- else[backcolor=Red]//为什么将else注释掉以后有的文件夹会被删两次?希望谁能解释一下?谢谢![/backcolor]
- System.out.println(files[x].toString()+"-file-"+files[x].delete());
- }
- System.out.println(dir+"::dir::"+dir.delete());
- }
- }
复制代码 |