Commit c1cde5f9 by tannongchun

修改内容

parent 5815c54d
package com.jtyjy.pdf2pptx.application;
import com.jtyjy.pdf2pptx.service.ConverterService;
import com.jtyjy.pdf2pptx.support.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
@Component
public class AppListener implements ApplicationListener<ContextRefreshedEvent> {
@Value("${file.path}")
private String filepath;
private final static Logger logger = LoggerFactory.getLogger(AppListener.class);
@Autowired
private ConverterService converterService;
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
System.err.println("正在处理 " + filepath);
System.err.println("处理开始 " + new Date());
converterService.converterPdf2Pptx(filepath);
System.err.println("处理完成 " + new Date());
}
}
......@@ -23,9 +23,17 @@ public class Pdf2Pptx {
public static void main(String[] args) {
//读取指定文件夹下所有文件并转换为图片
// conver(Constant.SOURCE_PATH);
//删除所有生成的图片文件
List<String> allDirPathName = new ArrayList<>();
FileUtil.getAllDirPathNameRe(Constant.SOURCE_PATH, allDirPathName);
for (String delFolder : allDirPathName) {
if (delFolder(delFolder)) {
logger.info("删除文件夹:{}及其文件成功", delFolder);
}
}
}
public void converte(String path){
public void converte(String path) {
conver(path);
}
......@@ -80,6 +88,59 @@ public class Pdf2Pptx {
}
}
//删除所有生成的图片文件
for (String dirPathName : allDirPathName) {
if (delFolder(dirPathName)) {
logger.info("删除文件夹:{}及其文件成功", dirPathName);
}
}
}
//删除指定文件夹下所有文件
public static boolean delAllFile(String path) {
boolean flag = false;
File file = new File(path);
if (!file.exists()) {
return flag;
}
if (!file.isDirectory()) {
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
if (path.endsWith(File.separator)) {
temp = new File(path + tempList[i]);
} else {
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile()) {
temp.delete();
}
if (temp.isDirectory()) {
delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件
delFolder(path + "/" + tempList[i]);//再删除空文件夹
flag = true;
}
}
return flag;
}
//删除文件夹
//param folderPath 文件夹完整绝对路径
public static boolean delFolder(String folderPath) {
try {
delAllFile(folderPath); //删除完里面所有内容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
return myFilePath.delete(); //删除空文件夹
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
......@@ -6,6 +6,6 @@ public class Constant {
* 待读取文件根目录
*/
// public static String SOURCE_PATH = "F:\\测试文档";
public static String SOURCE_PATH = "F:\\高二";
public static String SOURCE_PATH = "D:\\document";
}
# 注意斜杠
file:
path: D:\\document
\ No newline at end of file
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