用http大文件下载问题(20M以上) 在线等!

A_S478 2013-01-14 09:59:46
outStream = new BufferedOutputStream(response.getOutputStream(),1024*1024);
outStream.write(bytes,0,bytes.length);
response.flushBuffer();
outStream.close();
response.getOutputStream()输出时客户端最多只能接收到16277kb,缓存大小设的超过16277就会无效。
...全文
768 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
A_S478 2013-01-15
  • 打赏
  • 举报
回复
引用 10 楼 zzvnzz 的回复:
Java code ? 12345678910111213141516 InputStream in = getServletContext().getResourceAsStream("/WEB-INF/hadoop-2.0.2-alpha.tar.gz"); resp.setContentType("application/octet-stream")……
k可以,我的问题找到了,是客户端写入处理问题, con = (HttpURLConnection) url.openConnection(); inbuf = new BufferedInputStream (con.getInputStream()); System.out.println(inbuf.available()+"写入流的大小"); 不太明白inbuf.available()是只什么,似乎不是inbuf流的大小
yktd26 2013-01-15
  • 打赏
  • 举报
回复
这样发文件不是个办法啊。最好用apache,如果需要对文件进行保护,可以用xsendfile或者auth_token
渔丶 2013-01-15
  • 打赏
  • 举报
回复
引用 13 楼 A_S478 的回复:
引用 10 楼 zzvnzz 的回复: Java code ? 12345678910111213141516 InputStream in = getServletContext().getResourceAsStream("/WEB-INF/hadoop-2.0.2-alpha.tar.gz"); resp.setContentType("appli……
an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.
A_S478 2013-01-14
  • 打赏
  • 举报
回复
引用 2 楼 zzvnzz 的回复:
你代码写错了吧? Java code ? 1 response.flushBuffer();不是这个 Java code ? 12345678910111213141516 InputStream in = getServletContext().getResourceAsStream("/WEB-INF/hadoop-2.0.2-……
这样循环推送是没问题,但只适用小附件下载,一旦超过40M就不行了
A_S478 2013-01-14
  • 打赏
  • 举报
回复
我是从客户端抓取的,比较好控制,
引用 4 楼 anchor1 的回复:
可以使用push推送,一段一段推。
push推送没用过能详细点不
聪头 2013-01-14
  • 打赏
  • 举报
回复
可以使用push推送,一段一段推。
think201306 2013-01-14
  • 打赏
  • 举报
回复
用SmartUpload的试一下
渔丶 2013-01-14
  • 打赏
  • 举报
回复
你代码写错了吧?
 response.flushBuffer();
不是这个

InputStream in = getServletContext().getResourceAsStream("/WEB-INF/hadoop-2.0.2-alpha.tar.gz");
		
		resp.setContentType("application/octet-stream");
		resp.addHeader("Content-Disposition", "attachment;filename=" + new String("hadoop-2.0.2-alpha.tar.gz".getBytes("utf-8"),"ISO-8859-1"));
		resp.addHeader("Content-Length", "" + in.available());
		
		OutputStream out = resp.getOutputStream();
		int len=0;
		byte[] b= new byte[512];
		while((len=in.read(b))>0){
			out.write(b, 0, len);
		}
		out.flush();
		out.close();
		in.close();
A_S478 2013-01-14
  • 打赏
  • 举报
回复
有人没
大板牙花生 2013-01-14
  • 打赏
  • 举报
回复
学习下,同时求关于JSP中涉及到的常用类,最好能有列表列出来当手册查询用。
朱超ZhuChao.Tech 2013-01-14
  • 打赏
  • 举报
回复
可以是可以,最好前端加个APACHE。
渔丶 2013-01-14
  • 打赏
  • 举报
回复

InputStream in = getServletContext().getResourceAsStream("/WEB-INF/hadoop-2.0.2-alpha.tar.gz");

		resp.setContentType("application/octet-stream");
		resp.addHeader("Content-Disposition", "attachment;filename=" + new String("hadoop-2.0.2-alpha.tar.gz".getBytes("utf-8"), "ISO-8859-1"));
		resp.addHeader("Content-Length", "" + in.available());

		OutputStream out = resp.getOutputStream();
		int len = 0;
		byte[] b = new byte[512];
		while ((len = in.read(b)) > 0) {
			out.write(b, 0, len);
			out.flush();
		}
		out.close();
		in.close();
out.flush();放循环里面,下载268M文件,亲测可用!
A_S478 2013-01-14
  • 打赏
  • 举报
回复
random = new RandomAccessFile(filepath,"r"); File file=new File(filepath); channel = random.getChannel(); long fileSize = random.length(); //锟侥硷拷锟斤拷小 filepath = new String(filepath.getBytes("gb2312"), "ISO8859-1"); response.setContentLength((int) fileSize); bytes= new byte[(int)(outSize-startsSize)]; MappedByteBuffer out =channel.map(MapMode.READ_ONLY,(startsSize),(outSize)); out.get(bytes); //把out拷贝到bytes数组 clean(out); //清空out System.out.println(out+"out"); if( channel != null){ channel.close(); } if (random != null) { random.close(); } if (inputStreamReader != null) { inputStreamReader.close(); } outStream = new BufferedOutputStream(response.getOutputStream()); outStream.write(bytes,0,bytes.length); response.flushBuffer(); outStream.close(); 上面是服务端的读取文件和流输出
A_S478 2013-01-14
  • 打赏
  • 举报
回复
引用 7 楼 quzhihuijingjing 的回复:
不是代码写错了,有些框架对文件下载做了限制,需要修改相应的配置。 去百度一下:如何修改struts2下载文件配置大小
struts2我没用到,用的是servlet做服务端,tomcat做服务器
quzhihuijingjing 2013-01-14
  • 打赏
  • 举报
回复
不是代码写错了,有些框架对文件下载做了限制,需要修改相应的配置。 去百度一下:如何修改struts2下载文件配置大小

81,122

社区成员

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

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