67,513
社区成员
发帖
与我相关
我的任务
分享
public void downloadLocal(HttpServletResponse response, String alarmTypeName) throws FileNotFoundException{
// 下载本地文件
String fileName = alarmTypeName;
fileName += (".xls").toString();
try{
fileName = URLEncoder.encode(fileName, "UTF-8");
// 读到流中
InputStream inStream = new FileInputStream("D://alarmTotalInfo//totalInfo.xls");// 文件的存放路径
// 设置输出格式
response.reset();
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "inline;filename =" + fileName);
//response.addHeader("Content-Disposition", "attachment; filename=" + fileName);
// 循环取出流中的数据
byte[] b = new byte[1024];
int len;
try{
OutputStream out = response.getOutputStream(); // 获得输出
while ((len = inStream.read(b)) > 0){
out.write(b, 0, len);
}
out.flush();
out.close();
inStream.close();
}catch(IOException e){
e.printStackTrace();
}
}catch(Exception e){
e.printStackTrace();
}
}