救助各位高手!急!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() {
}
}
...全文
67 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
rootcn 2004-11-23
好像可以结0分贴,你看看怎么结...
回复
whyy0 2004-11-23
有办法自己拿吗?
回复
wanz0607 2004-09-26
分我自己拿了,我少了循环,麻烦大家了,呵呵
回复
vision2000 2004-09-23
up
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-22 12:12
社区公告
暂无公告