diff --git a/src/main/java/com/gunshi/project/xyt/controller/OsmoticWaterRController.java b/src/main/java/com/gunshi/project/xyt/controller/OsmoticWaterRController.java index bb9128c..58f09cf 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/OsmoticWaterRController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/OsmoticWaterRController.java @@ -1,6 +1,5 @@ package com.gunshi.project.xyt.controller; -import cn.hutool.core.io.resource.ClassPathResource; import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; @@ -38,21 +37,17 @@ import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; -import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; /** * 描述: 水质采样记录表 @@ -195,16 +190,16 @@ public class OsmoticWaterRController { @PostMapping("/downloadFile") @CrossOrigin public void downloadFile(HttpServletResponse response) throws IOException { - ClassPathResource classPathResource = new ClassPathResource("/doc/2002年6月1日_GB3838-2002地表水环境质量标准.pdf"); - File file = classPathResource.getFile(); + String filePath = "doc/2002年6月1日_GB3838-2002地表水环境质量标准.pdf"; + File file = new File(filePath); if (!file.exists()) { - new IllegalArgumentException("文件不存在!"); + new FileNotFoundException("文件不存在!"); } - response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8")); - BufferedInputStream inputStream = null; + response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filePath, "UTF-8")); + InputStream inputStream = null; OutputStream outputStream = null; try { - inputStream = new BufferedInputStream(new FileInputStream(file)); + inputStream = this.getClass().getClassLoader().getResourceAsStream(filePath); outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; int len = 0;