Browse Source

移动文件

lgs 11 months ago
parent
commit
d6b5bf8ddf

+ 9 - 2
src/main/java/com/kexun/service/impl/XmlFileHandlerServiceImpl.java

@@ -9,6 +9,7 @@ import com.kexun.model.Request;
 import com.kexun.service.ReportInfoService;
 import com.kexun.service.XmlFileHandlerService;
 import lombok.extern.log4j.Log4j;
+import org.apache.commons.io.FileUtils;
 import org.dom4j.*;
 import org.dom4j.io.SAXReader;
 import org.omg.CORBA.IRObject;
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.*;
 
 /**
@@ -53,7 +55,7 @@ public class XmlFileHandlerServiceImpl implements XmlFileHandlerService {
                 File[] fileLists = files.listFiles();
                 if (fileLists != null) {
                     //创建目录文件路径
-                    File targetFile = new File(xmlBackPath);
+
                     for (File fileList : fileLists) {
                         //只处理xml文件
                         if (fileList.isFile() && fileList.getName().endsWith(".xml")) {
@@ -69,7 +71,12 @@ public class XmlFileHandlerServiceImpl implements XmlFileHandlerService {
                             reportStruct = JSON.parseObject(xmlJson, ReportStruct.class);
                             saveReportInfo(reportStruct);
                             //将该目录下的文件进行移动,移动到指定的备份目录
-                            file.renameTo(targetFile);
+                            File targetFile = new File(xmlBackPath+name);
+                            try {
+                                FileUtils.moveFile(file,targetFile);
+                            } catch (IOException e) {
+                                e.printStackTrace();
+                            }
                         }
                     }
                 } else {

+ 15 - 3
src/test/java/Test3And6.java

@@ -1,5 +1,9 @@
 import com.kexun.model.LastFiveModel;
+import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.Test;
 
+import java.io.File;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
@@ -13,7 +17,17 @@ import java.util.List;
 public class Test3And6 {
 
 
-    public void test(){
+    @Test
+    public void test1() throws IOException {
+
+        File files = new File("/Users/lgs/work/xml/冯学娇_450923200204205360_593513420431565831-202305211850426247.xml");
+        File file = new File("/Users/lgs/work/back/冯学娇_450923200204205360_593513420431565831-202305211850426247.xml");
+        boolean b = files.renameTo(file);
+       FileUtils.moveFile(files,file);
+
+    }
+
+    public void test() {
 
         List<LastFiveModel> listD1 = new ArrayList<>();
 
@@ -46,8 +60,6 @@ public class Test3And6 {
         lastFiveModelD1_4.setTotAcctBal(new BigDecimal("0"));
         listD1.add(lastFiveModelD1_4);
 
-
-
     }
 
 }