Java编写定时删除文件程序
/*Java教程:http://www.javaweb.cc*/
import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class FileDeleter extends TimerTask {
private static final String targetPath1 = "C:\\Program Files\\Tencent\\QQ\\.......\\image";
private static final String targetPath2 = "C:\\Program Files\\Tencent\\QQ\\...........\\QQPhoto";
private Timer timer = new Timer();
private Calendar calendar = Calendar.getInstance();
public static void main(String[] args) {
FileDeleter fm = new FileDeleter();
fm.start();
}
private static void delFiles(String[] dir) {
for (int i = 0; i < dir.length; i++) {
File f = new File(dir[i]);
File[] files = null;
if (f.exists()) {
files = f.listFiles();
for (int j = 0; j < files.length; j++) {
files[j].delete();
}
}