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/controller/LicenseController.java | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/whyc/controller/LicenseController.java b/src/main/java/com/whyc/controller/LicenseController.java index 67a8167..e8f545f 100644 --- a/src/main/java/com/whyc/controller/LicenseController.java +++ b/src/main/java/com/whyc/controller/LicenseController.java @@ -184,6 +184,7 @@ fileName = ActionUtil.filterFileName(fileName); ClassPathResource classPathResource = new ClassPathResource("/config/"+fileName); InputStream inputStream_pub = null; + FileOutputStream fos=null; ApplicationHome applicationHome = new ApplicationHome(LicenseController.class); File jarFile = applicationHome.getDir(); String fileDirName = jarFile.getParentFile().toString()+ File.separator+"ksm"; @@ -191,16 +192,31 @@ createFile(fileDirName);//鍒涘缓鏂囦欢澶筴sm try { inputStream_pub = classPathResource.getInputStream(); - FileOutputStream fos = new FileOutputStream(fileDirName+"/"+fileName); + fos = new FileOutputStream(fileDirName+"/"+fileName); byte[] b = new byte[1024]; int length; while((length = inputStream_pub.read(b))>0){ fos.write(b,0,length); } - inputStream_pub.close(); + fos.close(); } catch (IOException e) { e.printStackTrace(); + }finally { + if(inputStream_pub!=null){ + try { + inputStream_pub.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if(fos!=null){ + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } return fileDirName; } -- Gitblit v1.9.1