[java]代码库
import java.io.File;
import java.util.Timer;
import java.util.TimerTask;
public class DelFile extends TimerTask {
public Timer time;
public DelFile(Timer time) {
super();
this.time=time;
}
@Override
public void run() {
File file = new File("E:\\a");
delFolder(file);
time.cancel();//完成指定时间删除后,停止运行
}
public void delFolder(File src) {
File[] files = src.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
delFolder(file);//循环删除
} else {
file.delete();
}
}
}
src.delete();
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
public class TimerTest {
public static void main(String[] args) throws Exception {
Timer t=new Timer();
String str="2017-11-15 16:16:40";
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d=sdf.parse(str);
t.schedule(new DelFile(t), d);
}
}