// 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();
}
}
如果觉得《java 后台将英文名 转换成中文名》对你有帮助,请点赞、收藏,并留下你的观点哦!