浏览器中跳出打开保存框

try {
// String file =request.getRealPath("D:\\aa.xlsx");

// String file= request.getRealPath("D:\\aa.xlsx");

File file = new File("/cpic/cpicapp/model/信托/产品分类.xls");

InputStream is = new FileInputStream(file);

//设置跳出打开保存取消框的名字

String fileName = java.net.URLEncoder.encode(file.getName(),"utf-8");

//弹出是否保存的对话框,括号内的内容不可更改

response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setContentType("application/vnd.ms-excel");//根据个人需要,这个是下载文件的类型
// response.reset(); // 必要地清除response中的缓存信息
OutputStream out = response.getOutputStream();
byte[] content = new byte[1024];
int length = 0;
while ((length = is.read(content)) != -1) {
out.write(content, 0, length);
}
out.flush();
is.close();
out.close();
} catch (Exception e) {
System.out.println("下载失败");
}

你可能感兴趣的:(浏览器中跳出打开保存框)