编程高手看看这个代码是讲什么?
代码实现:public class DownServlet extends HttpServlet {
private static final long serialVersionUID = 1332534778678L;
private static final int byte_size = 1024;
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentLength(byte_size); // 输出到客户端的文件大小
String fileName = "default.dmh";
response.setContentType("text/plain");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment; filename="
+ fileName); // 设置文件头
String url = request.getParameter("url");
URL fileUrl = new URL(url);
HttpURLConnection httpCon = (HttpURLConnection) fileUrl
.openConnection();
// System.out.println("before range.......... "+httpCon.getResponseCode());
String sProperty = "bytes=10-" + byte_size; // -后面表示要取多少数据
httpCon.setRequestProperty("RANGE", sProperty); // 设置偏移量
System.out.println("after range.......... "+httpCon.getResponseCode());
InputStream in = httpCon.getInputStream();
System.out.println("after InputStream.......... "+httpCon.getResponseCode());
DataInputStream dis = new DataInputStream(in); // 重新包装输入流
OutputStream out = response.getOutputStream(); // 从httpUrlConnecction中获得输出流
byte[] b = new byte; // 读取多少
dis.read(b);
out.write(b);
out.flush();
out.close(); // 关闭输入输出流
dis.close();
in.close();
}
} 顶!!! 顶!!! 不懂哦,等高人来回答。 文件传输 晕 你自己编译一下运行看看不就知道了啊:) 看不懂哦。。。。。。。。 等高人。 文件传输.支持断点续传
页:
[1]