8 changed files with 73 additions and 14 deletions
@ -0,0 +1,52 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import org.springframework.core.io.ClassPathResource; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.*; |
|||
import java.net.URL; |
|||
import java.net.URLConnection; |
|||
import java.net.URLEncoder; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@RestController |
|||
@RequestMapping("/download") |
|||
public class DownLoadFileController { |
|||
|
|||
/** |
|||
* @param response |
|||
* @功能描述 下载文件: |
|||
*/ |
|||
@RequestMapping("/download") |
|||
public void download(HttpServletRequest request,HttpServletResponse response) { |
|||
try { |
|||
ClassPathResource classPathResource = new ClassPathResource("static/upload/PrintServer.zip"); |
|||
File file = classPathResource.getFile(); |
|||
InputStream inputStream = classPathResource.getInputStream(); |
|||
//输出文件
|
|||
InputStream fis = new BufferedInputStream(inputStream); |
|||
byte[] buffer = new byte[fis.available()]; |
|||
fis.read(buffer); |
|||
fis.close(); |
|||
response.reset(); |
|||
|
|||
//获取文件的名字再浏览器下载页面
|
|||
String name = file.getName(); |
|||
response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1")); |
|||
response.addHeader("Content-Length", "" + file.length()); |
|||
OutputStream out = new BufferedOutputStream(response.getOutputStream()); |
|||
response.setContentType("application/octet-stream"); |
|||
out.write(buffer); |
|||
out.flush(); |
|||
out.close(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue