救助各位高手!急!servlet下载问题!
本是一个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() {
}
}