jsp下载 java BufferedInputStream 读取excel文件 这样就不出...
2013-10-30 00:00
489 查看
//下载
response.setContentType("text/html;charset=utf-8");
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
String downLoadPath ="c:\\huiyuan.xls";
try {
long fileLength = new File(downLoadPath).length();
response.setContentType("application/x-msdownload;");
response.setHeader("Content-disposition", "attachment; filename="
+ new String("会员管理名单.xls".getBytes("utf-8"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(fileLength));
bis = new BufferedInputStream(new FileInputStream(downLoadPath));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if(bis!=null)
bis.close();
if(bos!=null)
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
response.setContentType("text/html;charset=utf-8");
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
String downLoadPath ="c:\\huiyuan.xls";
try {
long fileLength = new File(downLoadPath).length();
response.setContentType("application/x-msdownload;");
response.setHeader("Content-disposition", "attachment; filename="
+ new String("会员管理名单.xls".getBytes("utf-8"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(fileLength));
bis = new BufferedInputStream(new FileInputStream(downLoadPath));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if(bis!=null)
bis.close();
if(bos!=null)
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
相关文章推荐
- 读取excel文件(jxl.jar包简介/java操作excel jxl.jar下载地址)
- java 读取简单文件的内容 InputStreamReader BufferedReader
- jsp里使用java excel api实现文件下载
- java文件读取(按字符读+按字节读+缓冲读取)FileReader FileInputStream BufferedReader
- java 读取Excel处理并在网页下载处理后的新文件
- JSP+Java+properties+FileInputStream文件读写,JSP页面读取properties文件
- JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法
- Java BufferedInputStream与BufferedOutputStream 入门版实例解析【文件操作】
- JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法
- JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法
- Java file文件的写入和读取及下载
- java中读取excel文件中字符串乱码问题解决方法
- 两行解决java读取excel文件内数字显示为小数点或者科学计数法问题
- jsp页面 java 文件下载设置禁止IE直接打开配置问题
- 从JAVA直接读取EXCEL、WORD并生成PDF文件
- 为什么java读取配置文件,中文这样不会出现乱码
- JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法
- java中BufferedReader读取文件中有特殊符号的方法
- java下载的excel显示发现不可读取的内容。是否恢复此工作薄的内容?如果信任此工作薄的来源,请单击‘是’。”
- 生成/读取(反向更新数据库) Excel文件(示例代码下载)