救助各位高手!急!servlet下载问题!

wanz0607 2004-09-22 12:12:33
本是一个REALONE播放程序,其实是一个边读边写的下载功能。问题在于,我读一个20M的RM格式的文件,下载的时候不显示文件大小,而且下载速度的单位是MB/秒,一直下载到4GB的时候才停止,麻烦高手请指示,以下是代码:

package com.fzd.lms.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class ServletPlay extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//获取文件类型
response.setContentType("application/vnd.rn-realmedia; charset=GBK");


BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try{

File path = new File("i:\\课程\\a\\001\\");

File file = new File(path,"01.rm");

bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(response.getOutputStream());

byte[] buff = new byte[2048];
int bytesRead = bis.read(buff, 0, buff.length);

while(-1 != bytesRead) {
bos.write(buff,0,bytesRead);
}

}
catch(IOException e) {
System.out.println ( "出现错误1:" + e.getMessage() );
}catch(Exception e1) {
System.out.println ( "出现错误2:" + e1.getMessage());
}

finally {

try{
if (bis != null) bis.close();
if (bos != null) bos.close();
}catch(Exception er){
System.out.println ("出现错误3:" + er.getMessage());

}


}

}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}
...全文
101 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
rootcn 2004-11-23
  • 打赏
  • 举报
回复
好像可以结0分贴,你看看怎么结...
whyy0 2004-11-23
  • 打赏
  • 举报
回复
有办法自己拿吗?
wanz0607 2004-09-26
  • 打赏
  • 举报
回复
分我自己拿了,我少了循环,麻烦大家了,呵呵
vision2000 2004-09-23
  • 打赏
  • 举报
回复
up

81,122

社区成员

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

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