下载问题

yanhuoyanyi 2008-01-16 09:59:29
我在做下载的时候有的文件下载不了.例如超过20M的东西我都不能下载是什么原因有人能帮我解决一下吗

java.io.BufferedInputStream bis=null;
java.io.BufferedOutputStream bos=null;
try{
DoradoContext context = DoradoContext.getContext();
ServletContext servletContext = ((HttpDoradoContext) context).getRequest().getSession().getServletContext();
String docRoot = servletContext.getRealPath("/");
String path = new String(request.getParameter("FilePath").getBytes("ISO-8859-1"), "GBK");
String filepath=docRoot+path;
String filename = new String(request.getParameter("ReportName").getBytes("ISO-8859-1"), "GBK");
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gb2312"),"iso8859-1"));
bis =new java.io.BufferedInputStream(new java.io.FileInputStream(filepath));
bos=new java.io.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();
}
finally {
if (bis != null)bis.close();
if (bos != null)bos.close();
}
...全文
73 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
邻里亲戚 2008-07-31
  • 打赏
  • 举报
回复
用jspsmartupload吧,能解决你的问题
老紫竹 2008-01-16
  • 打赏
  • 举报
回复
你不会用ultraedit 打开啊! editplus 也行啊
yanhuoyanyi 2008-01-16
  • 打赏
  • 举报
回复
打开不了.提示下载文件已被损坏.
我尝试了。只要下载文件大于20M以后都有这个问题.
老紫竹 2008-01-16
  • 打赏
  • 举报
回复
打开那个5K的文件看看吧!也许是其他信息呢!
yanhuoyanyi 2008-01-16
  • 打赏
  • 举报
回复
谢谢你,可问题还是没解决,他还是下5K
老紫竹 2008-01-16
  • 打赏
  • 举报
回复
尝试我4楼的代码看看!
yanhuoyanyi 2008-01-16
  • 打赏
  • 举报
回复
客户端现实,也有下载但是下载一个压缩包,他只下了5K.不知道什么原因
老紫竹 2008-01-16
  • 打赏
  • 举报
回复
直接用InputStream和OutputStream 看看!
还有你的下载不了是什么现象? 客户端不显示下载对话框?还是服务器报错?

  java.io.InputStream bis = null;
java.io.OutputStream bos = null;
try {
DoradoContext context = DoradoContext.getContext();
ServletContext servletContext = ((HttpDoradoContext) context).getRequest().getSession().getServletContext();
String docRoot = servletContext.getRealPath("/");
String path = new String(request.getParameter("FilePath").getBytes("ISO-8859-1"), "GBK");
String filepath = docRoot + path;
String filename = new String(request.getParameter("ReportName").getBytes("ISO-8859-1"), "GBK");
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition", "attachment; filename="
+ new String(filename.getBytes("gb2312"), "iso8859-1"));
bis = new java.io.FileInputStream(filepath);
bos = response.getOutputStream();
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
changjiangzhibin 2008-01-16
  • 打赏
  • 举报
回复
BT
yanhuoyanyi 2008-01-16
  • 打赏
  • 举报
回复
见笑了.我对线程一窍不通.能否高人指点下怎么试
lgwang_03 2008-01-16
  • 打赏
  • 举报
回复
考虑用多线程把文件分块下载试试
aguai0 2008-01-16
  • 打赏
  • 举报
回复
关注~!

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧