Pārlūkot izejas kodu

修改流未关闭

xusl 3 gadi atpakaļ
vecāks
revīzija
62e250777d

+ 13 - 5
ipfcst-common/ipfcst-common-core/src/main/java/com/jiayue/ipfcst/common/core/util/CommonUtil.java

@@ -132,12 +132,20 @@ public abstract class CommonUtil {
             zos.putNextEntry(new ZipEntry(name));
             // copy文件到zip输出流中
             int len;
-            FileInputStream in = new FileInputStream(sourceFile);
-            while ((len = in.read(buf)) != -1) {
-                zos.write(buf, 0, len);
+            FileInputStream in = null;
+            try {
+                in = new FileInputStream(sourceFile);
+                while ((len = in.read(buf)) != -1) {
+                    zos.write(buf, 0, len);
+                }
+                zos.closeEntry();
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                if (in != null) {
+                    in.close();
+                }
             }
-            zos.closeEntry();
-            in.close();
         } else {
             File[] listFiles = sourceFile.listFiles();
             if (listFiles == null || listFiles.length == 0) {

+ 6 - 2
ipfcst-console/src/main/java/com/jiayue/ipfcst/fileupload/util/ByteUtil.java

@@ -204,8 +204,12 @@ public abstract class ByteUtil {
       return null;
     }
     Formatter f = new Formatter();
-    for (byte b : ba) {
-      f.format("%02x ", b);
+    try {
+      for (int i = 0; i < ba.length; ++i) {
+        f.format("%02x ", ba[i]);
+      }
+    } finally {
+      f.close();
     }
     return f.toString();
   }