//點擊文件下app
@RequestMapping("/getFj")get
public void getFj(HttpServletResponse res, String fid,String fname) throws UnsupportedEncodingException { it
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService=processEngine.getRepositoryService(); res.setHeader("content-type", "application/octet-stream"); res.setContentType("application/octet-stream");io
//中文文件名不行,須要轉碼 stream
String file_name = new String(fname.getBytes(), "ISO-8859-1"); res.setHeader("Content-Disposition", "attachment;filename=" + file_name); coding
byte[] buff = new byte[1024]; file
BufferedInputStream bis = null; di
OutputStream os = null; 文件
try { os = res.getOutputStream(); ping
bis=new BufferedInputStream(repositoryService.getResourceAsStream(fid,fname));
int i = bis.read(buff);
while (i != -1) {
os.write(buff, 0, buff.length);
os.flush(); i = bis.read(buff);
} }
catch (IOException e) {
e.printStackTrace(); }
finally { if (bis != null) {
try { bis.close(); }
catch (IOException e) { e.printStackTrace(); } } } }