下载txt文件
来源:互联网 发布:js键盘事件代码 编辑:程序博客网 时间:2024/04/25 00:27
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// String filename = request.getParameter("filename");//"1a.txt";
// String filepath = request.getParameter("filepath");//"d:\\";
// System.out.println(filename);
// System.out.println(filepath);
String filepath=request.getSession().getServletContext().getRealPath("");
System.out.println("===jia"+filepath);
filepath=filepath+"\\fileUpload\\default\\mail\\";
String filename="2.xls";
File file=new File(filepath+filename);
if(!file.exists()){
response.sendError(404, "没有找到资源Rain Rocky");
}
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
//response.setContentType("image/bitmap");
//下面这句 点击连接时 提供下载提示;没有这句的话 点击连接在窗口中打开资源
response.setHeader("Content-Disposition","attachment;filename ="+filename);
try{
InputStream is = new FileInputStream(file);
BufferedInputStream bis=new BufferedInputStream(is);
BufferedOutputStream out=new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int i = 0;
while((i= bis.read(buff,0,buff.length)) != -1){
out.write(buff,0,i);
}
out.close();
bis.close();
}catch (Exception e) {
}
}
throws ServletException, IOException {
// String filename = request.getParameter("filename");//"1a.txt";
// String filepath = request.getParameter("filepath");//"d:\\";
// System.out.println(filename);
// System.out.println(filepath);
String filepath=request.getSession().getServletContext().getRealPath("");
System.out.println("===jia"+filepath);
filepath=filepath+"\\fileUpload\\default\\mail\\";
String filename="2.xls";
File file=new File(filepath+filename);
if(!file.exists()){
response.sendError(404, "没有找到资源Rain Rocky");
}
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
//response.setContentType("image/bitmap");
//下面这句 点击连接时 提供下载提示;没有这句的话 点击连接在窗口中打开资源
response.setHeader("Content-Disposition","attachment;filename ="+filename);
try{
InputStream is = new FileInputStream(file);
BufferedInputStream bis=new BufferedInputStream(is);
BufferedOutputStream out=new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int i = 0;
while((i= bis.read(buff,0,buff.length)) != -1){
out.write(buff,0,i);
}
out.close();
bis.close();
}catch (Exception e) {
}
}
- .txt文件的下载
- 下载txt文件
- txt文件下载
- PHP 下载txt文件
- php点击下载txt文件
- php点击下载txt文件
- .xls .txt文件生成下载
- jsp页面下载txt文件
- PHP 下载txt文件 功能
- jsp 下载txt文件和excel文件
- 动态生成.txt文件并提供下载
- js 下载 txt文件的解决方法
- ie下载 txt文件的解决方法
- [ASP.NET]下载txt格式的文件
- jsp生成 文件下载 比如txt
- java导出Txt文件怎么下载
- Java生成Txt文件及下载
- PHP生成TXT的下载文件
- apache的httpd.conf文件配置和第一个php程序
- (六) MySQL存储过程
- [oracle10g] 更改字符集AL32UTF8为ZHS16GBK .
- 求一个字符串中连续出现次数最多的子串
- web工程师的几个阶段
- 下载txt文件
- Android浏览页面时报数据连接性问题
- 控制台程序下文件夹文件遍历
- Java常见异常(Runtime Exception )小结
- c#,sql 中 datatime 类型的格式
- 51单片机(AT89C52)定时器
- Struts2 Action的访问路径
- RMI@Spring的常见问题解决
- JavaWeb Socket 通信优化设置