| | |
| | | |
| | | import cc.mrbird.febs.common.core.exception.FebsException; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.lang.Dict; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import cn.hutool.core.io.FileUtil; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.zip.ZipEntry; |
| | |
| | | public class MyUtil { |
| | | |
| | | public static void downloadFile(File file, HttpServletResponse response) throws IOException { |
| | | InputStream fin = null; |
| | | ServletOutputStream out = null; |
| | | try { |
| | | fin = new FileInputStream(file); |
| | | out = response.getOutputStream(); |
| | | try (InputStream fin = new FileInputStream(file); ServletOutputStream out = response.getOutputStream()) { |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setContentType("application/x-download"); |
| | | response.addHeader("Content-Disposition", "attachment;filename=resume.doc"); |
| | |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesToRead = -1; |
| | | // 通过循环将读入的Word文件的内容输出到浏览器中 |
| | | while((bytesToRead = fin.read(buffer)) != -1) { |
| | | while ((bytesToRead = fin.read(buffer)) != -1) { |
| | | out.write(buffer, 0, bytesToRead); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("下载文件异常" + e); |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if(fin != null) fin.close(); |
| | | if(out != null) out.close(); |
| | | |
| | | } |
| | | } |
| | | |