From cba96d4cbd3ddd8af20b2d65d1f430c75f667821 Mon Sep 17 00:00:00 2001 From: lxw <810412026@qq.com> Date: 星期三, 22 十一月 2023 11:43:43 +0800 Subject: [PATCH] 2.2.9资源未释放 --- src/main/java/com/whyc/util/ActionUtil.java | 35 ++++++++++++++++++++++++++--------- 1 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/whyc/util/ActionUtil.java b/src/main/java/com/whyc/util/ActionUtil.java index c1118fc..32d103a 100644 --- a/src/main/java/com/whyc/util/ActionUtil.java +++ b/src/main/java/com/whyc/util/ActionUtil.java @@ -422,10 +422,17 @@ inputStream = new FileInputStream(imgFile); data = new byte[inputStream.available()]; inputStream.read(data); - inputStream.close(); } catch (IOException e) { e.printStackTrace(); - } + }finally { + if(inputStream!=null){ + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } // 鍔犲瘑 BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(data); @@ -441,8 +448,10 @@ * @return */ public static boolean generateImage(String imgStr, String path) { - if (imgStr == null) { - return false; + boolean bl=false; + OutputStream out=null; + if (imgStr == null) { + bl=false; } BASE64Decoder decoder = new BASE64Decoder(); try { @@ -454,14 +463,22 @@ b[i] += 256; } } - OutputStream out = new FileOutputStream(path); + out = new FileOutputStream(path); out.write(b); out.flush(); - out.close(); - return true; + bl=true; } catch (Exception e) { - return false; - } + bl=false; + }finally { + if(out!=null){ + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return bl; } /** -- Gitblit v1.9.1