@RequestMapping("download")
public void download(HttpServletResponse response) throws IOException {
InputStream input = new FileInputStream(new File("E:\\520200.json"));
response.setContentType("application/octet-stream; charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename="+ Encodes.urlEncode("520200.json"));
copy(input,response.getOutputStream() );
}
/**
* 在InputStream与OutputStream间复制内容
*/
public static long copy(final InputStream input, final OutputStream output) throws IOException {
final byte[] buffer = new byte[1024];
long count = 0;
int n;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}