Commit 76441a2a authored by DESKTOP-BQLVS7A\admin's avatar DESKTOP-BQLVS7A\admin

ugp测试在服务器定时删除文件夹下的文件

parent 51ef7f2c
...@@ -6,7 +6,11 @@ import org.springframework.scheduling.annotation.Scheduled; ...@@ -6,7 +6,11 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;
@Component @Component
@EnableScheduling @EnableScheduling
...@@ -15,24 +19,46 @@ public class CylinderSchedulerJob { ...@@ -15,24 +19,46 @@ public class CylinderSchedulerJob {
/** /**
* 每天3点-删除图片 * 每天3点-删除图片
*/ */
@Scheduled(cron = "${cylinder-early-warning-cron:0 0 19 * * ?}") // @Scheduled(cron = "${cylinder-early-warning-cron:0 0 19 * * ?}")
public void clean() { // public void clean() {
dayReport(new File("/home/yeejoin/ugp/minio-data/upload/common/ugp/qrcode")); // dayReport(new File("/home/yeejoin/ugp/minio-data/upload/common/ugp/qrcode"));
} // }
public static void dayReport(File file) { // public static void dayReport(File file) {
// file.isAbsolute(); //// file.isAbsolute();
if (!ValidationUtil.isEmpty(file.listFiles())) { // if (!ValidationUtil.isEmpty(file.listFiles())) {
for (File f : file.listFiles()) { // for (File f : file.listFiles()) {
//实现递归 // //实现递归
if (f.isDirectory()) { // if (f.isDirectory()) {
dayReport(f); // dayReport(f);
} // }
//清理文件 // //清理文件
f.delete(); // f.delete();
System.out.println(f.getName() + "已清理!!!"); // System.out.println(f.getName() + "已清理!!!");
// }
// }
// }
@Scheduled(cron = "${cylinder-early-warning-cron:0 0 12 * * ?}")
public void cleanFile() throws IOException {
deleteFile("/home/yeejoin/ugp/minio-data/upload/common/ugp/ceshi");
} }
public static void deleteFile(String destDirPath) throws IOException {
System.out.println("开始删除文件 destDirPath:{}");
Process p;
InputStreamReader inputStreamReader = null;
BufferedReader br = null;
String co = "rm -rf " + destDirPath;
try {
p = Runtime.getRuntime().exec(co);
inputStreamReader = new InputStreamReader(p.getInputStream());
br = new BufferedReader(inputStreamReader);
System.out.println("执行删除任务完毕 删除命令:{} 时间:{}");
} catch (IOException e) {
throw new RuntimeException(e);
}finally {
br.close();
} }
} }
// public static void main(String[] args) { // public static void main(String[] args) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment