没有合适的资源?快使用搜索试试~ 我知道了~
输入流输出流方式的文件上传下载
1星 需积分: 50 37 下载量 43 浏览量
2012-11-12
16:30:43
上传
评论
收藏 4KB TXT 举报
温馨提示
试读
5页
通过输入流输出流方式的文件上传下载 代码写的可能糙了一点 但是远离还是一眼就能看明白的
资源推荐
资源详情
资源评论
1.<%@page language="java" contentType="application/x-msdownload" pageEncoding="gb2312"%>
2.<%
3. //关于文件下载时采用文件流输出的方式处理:
4. //加上response.reset(),并且所有的%>后面不要换行,包括最后一个;
5.
6. response.reset();//可以加也可以不加
7. response.setContentType("application/x-download");
8.
9.//application.getRealPath("/main/mvplayer/CapSetup.msi");获取的物理路径
10.
11.String filedownload = "想办法找到要提供下载的文件的物理路径+文件名";
12. String filedisplay = "给用户提供的下载文件名";
13. String filedisplay = URLEncoder.encode(filedisplay,"UTF-8");
14. response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
15.
16. java.io.OutputStream outp = null;
17. java.io.FileInputStream in = null;
18. try
19. {
20. outp = response.getOutputStream();
21. in = new FileInputStream(filenamedownload);
22.
23. byte[] b = new byte[1024];
24. int i = 0;
25.
26. while((i = in.read(b)) > 0)
27. {
28. outp.write(b, 0, i);
29. }
30.//
2.<%
3. //关于文件下载时采用文件流输出的方式处理:
4. //加上response.reset(),并且所有的%>后面不要换行,包括最后一个;
5.
6. response.reset();//可以加也可以不加
7. response.setContentType("application/x-download");
8.
9.//application.getRealPath("/main/mvplayer/CapSetup.msi");获取的物理路径
10.
11.String filedownload = "想办法找到要提供下载的文件的物理路径+文件名";
12. String filedisplay = "给用户提供的下载文件名";
13. String filedisplay = URLEncoder.encode(filedisplay,"UTF-8");
14. response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
15.
16. java.io.OutputStream outp = null;
17. java.io.FileInputStream in = null;
18. try
19. {
20. outp = response.getOutputStream();
21. in = new FileInputStream(filenamedownload);
22.
23. byte[] b = new byte[1024];
24. int i = 0;
25.
26. while((i = in.read(b)) > 0)
27. {
28. outp.write(b, 0, i);
29. }
30.//
资源评论
- happysean82013-03-01垃圾代码 差劲
wuhaoyu_dandan
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功