diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index a4161834b6..70c46f1f9e 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -104,9 +104,6 @@ public class APITestService { } private void createBodyFiles(ApiTest test, List bodyUploadIds, List bodyFiles) { - if (bodyFiles == null || bodyFiles.isEmpty()) { - - } String dir = BODY_FILE_DIR + "/" + test.getId(); File testDir = new File(dir); if (!testDir.exists()) { @@ -115,24 +112,12 @@ public class APITestService { for (int i = 0; i < bodyUploadIds.size(); i++) { MultipartFile item = bodyFiles.get(i); File file = new File(testDir + "/" + bodyUploadIds.get(i) + "_" + item.getOriginalFilename()); - InputStream in = null; - OutputStream out = null; - try { + try (InputStream in = item.getInputStream(); OutputStream out = new FileOutputStream(file)) { file.createNewFile(); - in = item.getInputStream(); - out = new FileOutputStream(file); FileUtil.copyStream(in, out); } catch (IOException e) { LogUtil.error(e); MSException.throwException(Translator.get("upload_fail")); - } finally { - try { - in.close(); - out.close(); - } catch (IOException e) { - LogUtil.error(e); - MSException.throwException(Translator.get("upload_fail")); - } } } }