文件原位置:
@RequestMapping("/downloadScript")
public ResponseEntity<byte[]> download(HttpServletRequest request){
try{
String path = request.getSession().getServletContext().getRealPath("/") + "/upload/scripts/script.zip";
File file=new File(path);
byte[] body=null;
InputStream is=new FileInputStream(file);
body=new byte[is.available()];
is.read(body);
HttpHeaders httpHeaders=new HttpHeaders();
httpHeaders.add("Content-Disposition","attchement;filename="+file.getName());
HttpStatus statusCode= HttpStatus.OK;
ResponseEntity<byte[]> entity=new ResponseEntity<byte[]>(body,httpHeaders,statusCode);
return entity;
}catch (Exception e){
e.printStackTrace();
}
return null;
}