@SupperssWarnigs("resource")
public ResponseEntity<byte[]> downLoadFile(String filePath)throws IOException,FileNotFoundException{
filePath=filepath.replace("/","\\");
File f=new File(filePath);
byte[] body=null;
InputStream is;
try{
is=new FileInputStream(f);
body=new byte[is.available()];
is.read(body);
HttpHeaders headers=new HttpHeaders();
String fileName=filePath.substring(filePath.lastIndexOf("\\")+1);
fileName=new String(fileName.getBytes("utf-8"),"ios-8859-1");
headers.add("Content-Disposition","attachment;filename="+filename);
headers.set("Content-Type","multipart/form-data");
ResponseEntity<byte[]> responseEntity=new ResponseEntity<byte[]>(body,headers,HttpStatus.ok);
return responseEntity;
}catch(FileNotFoundException e){
throw new FileNotFoundException();
}catch(IOException e){
}
}
文件下载
最新推荐文章于 2022-06-08 14:59:21 发布