java 後臺將英文名 轉換成中文名
阿新 • • 發佈:2019-01-11
// response.setContentType("application/x-msdownload");
//2.設定檔案頭:最後一個引數是設定下載檔名(假如我們叫a.pdf)
TClassUpload tcb=classUploadServiceImpl.findModel(cuid);
String name="XXX";
name = URLEncoder.encode(name, "UTF-8");
response.setHeader("Content-Disposition", "attachment;fileName="+name+".xls");
OutputStream out;
//通過檔案路徑獲得File物件()
File file = new File( request.getServletContext().getRealPath()+"//resources//template/projectMedel.xml");
try {
FileInputStream inputStream = new FileInputStream(file);
//3.通過response獲取ServletOutputStream物件(out)
out = response.getOutputStream();
int b = 0;
byte[] buffer = new byte[512];
b = inputStream.read(buffer);
while (b != -1){
//4.寫到輸出流(out)中
out.write(buffer,0,b);
b = inputStream.read(buffer);
}
inputStream.close();
out.close();
out.flush();
// tcb.setDownNum(tcb.getDownNum()+1);
// classBooksServiceImpl.updateModel(tcb);
} catch (IOException e) {
e.printStackTrace();
}
}