From 547b6ac144d0745d9b55526c062b2fcaeb80fe4e Mon Sep 17 00:00:00 2001
From: lxw <810412026@qq.com>
Date: 星期五, 16 九月 2022 11:13:09 +0800
Subject: [PATCH] 修改文件

---
 src/main/java/com/whyc/dto/XmlFileOpreate.java |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/whyc/dto/XmlFileOpreate.java b/src/main/java/com/whyc/dto/XmlFileOpreate.java
index b355601..2b5a730 100644
--- a/src/main/java/com/whyc/dto/XmlFileOpreate.java
+++ b/src/main/java/com/whyc/dto/XmlFileOpreate.java
@@ -25,7 +25,8 @@
         try
         {
             SAXReader reader = new SAXReader();
-            Document document = reader.read(new File(xmlFilePath));
+            FileInputStream  fiso=new FileInputStream(xmlFilePath);
+            Document document = reader.read(fiso);
             Element rootnode = document.getRootElement();
 
             Element node;//鏍硅妭鐐�
@@ -130,8 +131,11 @@
                 fileInfo.getBattInfoList().add(battInfo);
             }
             fileInfo.setFileParam(fparam);
-        } catch (NullPointerException | NumberFormatException | DocumentException | ParseException e) {
+            fiso.close();
+        } catch (NullPointerException | NumberFormatException | DocumentException | ParseException | FileNotFoundException e) {
             res = false;
+            e.printStackTrace();
+        } catch (IOException e) {
             e.printStackTrace();
         } finally {
             if(false == res)
@@ -144,11 +148,13 @@
         boolean res=true;
         try {
             SAXReader reader = new SAXReader();
-            Document document = reader.read(new File(xmlFilePath));
+            FileInputStream fiso= new FileInputStream(xmlFilePath);
+            Document document = reader.read(fiso);
 
             for (Map.Entry<String, String> entry:map.entrySet()) {
                 String mapKey = entry.getKey();
                 String mapValue = entry.getValue();
+                System.out.println(mapKey+":"+mapValue);
                 //寰楀埌绗竴涓猰apKey鑺傜偣
                 Node node=document.selectSingleNode("//"+mapKey);
                 node.setText(mapValue);
@@ -157,6 +163,8 @@
             format.setEncoding("UTF-8");//榛樿鐨勭紪鐮佸氨鏄疷TF-8
             XMLWriter writer = new XMLWriter( new FileOutputStream(xmlFilePath), format );
             writer.write( document );
+            writer.close();
+            fiso.close();
         } catch (DocumentException | FileNotFoundException | UnsupportedEncodingException e) {
             res = false;
             e.printStackTrace();

--
Gitblit v1.9.1