//Delete from folder with to date and from date springbootDelete from folder with to date and from date springbootDelete from folder with to date and from 日期springboot
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FileDeletionExample {
public static void main(String[] args) {
String folderPath = "path/to/folder"; // Specify the folder path
Date fromDate = /* specify the start date */;
Date toDate = /* specify the end date */;
File folder = new File(folderPath);
File[] files = folder.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
Date lastModifiedDate = new Date(file.lastModified());
if (lastModifiedDate.after(fromDate) && lastModifiedDate.before(toDate)) {
if (file.delete()) {
System.out.println("Deleted file: " + file.getName());
} else {
System.out.println("Failed to delete file: " + file.getName());
}
}
}
}
}
}
}