定時清理磁盤

taiwan-lingli-new
yiming 4 years ago
parent feece99ab5
commit 261284ded8

@ -24,11 +24,11 @@ public class CronTab {
private static LocalDateTime now;
//@Scheduled(cron = "0 0 0 * * ?")
@Scheduled(cron = "0 0/1 * * * *")
@Scheduled(cron = "0 0 0 * * ?")
//@Scheduled(cron = "0 0/1 * * * *")
public void file() {
log.info(" corn delete file");
now = LocalDateTime.now();
log.info(" corn delete file ,time:{}",now);
File dir = new File(configProperties.getSavePath().getMediaPath());
checkFileTime(dir,configProperties.getDeleteFileDays());
File dir2 = new File(configProperties.getSavePath().getMp4Path());
@ -36,7 +36,9 @@ public class CronTab {
}
public static void checkFileTime(File dir,int days) {
if(!dir.exists()){
return;
}
if (dir.isDirectory()) {
String[] children = dir.list();
if(children.length == 0){
@ -52,9 +54,11 @@ public class CronTab {
try {
Path path = dir.toPath();
attr = Files.readAttributes(path, BasicFileAttributes.class);
} catch (IOException e) {
e.printStackTrace();
}
if(attr != null){
// 创建时间
Instant instant = attr.creationTime().toInstant();
LocalDateTime createTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
@ -65,5 +69,6 @@ public class CronTab {
}
}
}
}
}

Loading…
Cancel
Save