1、代码:
response.setContentType("application/msword;charset=GBK");
try {
response.setHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("GBK"),"iso-8859-1"));
} catch (UnsupportedEncodingException e1) {
logger.error("头文件格式转换异常", e1);
}
try {
URL file = new URL(filepath + usepath);
InputStream inputStream = file.openStream();
OutputStream os = response.getOutputStream();
byte[] b = new byte[2048];
int length;
while ((length = inputStream.read(b)) > 0) {
os.write(b, 0, length);
}
//关闭。
os.close();
inputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}