非常危险的程序,慎重使用! import java.io.File; /** * FileDeleter * * @author TJ * */ public class FileDeleter { public static void main(String[] args) { if (args == null || args.length == 0) { System.out.println("please input the directory!"); return; } File directory = new File(args[0]); if (!directory.exists()) { System.out.println("directory is not exists."); return; } boolean flag = deleteAllFile(directory); if (flag) { System.out.println("success."); } else { System.out.println("fail."); } } /** * delete all file from directory. * * @param directory * @return result */ public static boolean deleteAllFile(File directory) { if (directory.isFile()) { System.out.println("please input the directory!"); return false; } File[] files = directory.listFiles(); for (File file : files) { if (file.isFile()) { file.delete(); } else { deleteAllFile(file); } } return true; } }