下载服务器端EXCEL
public void downLoad(HttpServletResponse response, HttpServletRequest request) {
String id = request.getParameter("id");// id
CownExcel cownExcel = customerService.getCownExcelID(Integer.parseInt(id));
try {
String filename = cownExcel.getUrl();
filename = filename.substring(filename.lastIndexOf("\\")+1);//获取文件名字某个路径下的
// 读到流中 InputStream inStream;
inStream = new FileInputStream(cownExcel.getUrl());//下载文件的路径
// 文件的存放路径 // 设置输出的格式
response.reset();
response.setContentType("bin");
try {
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); // 循环取出流中的数据 byte[] b = new byte[100]; int len;
try {
while ((len = inStream.read(b)) > 0)
response.getOutputStream().write(b, 0, len);
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } }