用IO流,多线程,网络编程这些怎样去实现简单的下载功能?实现简单下载就行,,有哪位朋友能讲一下思路,,有源代码的更好!

解决方案 »

  1.   

    有写好的框架lz为什么不用呢?jspsmart就很不错啊,为什么不试一试呢?
      

  2.   

    给你一个我早上回答问题的例子吧,
    用JSP下载Excel文件
    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <%@ page import="java.util.*,java.io.*"%>
    <%
      out.clearBuffer();
      try {
        String path = "e:/";
        String fileName = "test.xls";
        response.setContentType("application/vnd.ms-excel");
        String fileBar = System.getProperty("file.separator");
        response.addHeader("Content-Disposition", "attachment;filename=" + fileBar + fileName);
        FileInputStream is = new FileInputStream(path+fileName);
        OutputStream os = response.getOutputStream();
        byte[] bs = new byte[2048];
        int len = 0;
        while ((len = is.read(bs)) != -1) {
          os.write(bs, 0, len);
        }
        is.close();
        os.close();
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    %>
      

  3.   

    google,baidu搜索也不用.可以看下,
    Java实现HTTP文件下载:http://dev.csdn.net/author/alexjjf/13cff18eec784e4baca3fb315542d58e.html
      

  4.   

    那些框架还没学呀。。就用J2SE的上面那些怎么实现呀。大家都说说,分不够再加。。
      

  5.   

    源码:http://blog.csdn.net/fastunit/archive/2008/01/23/2061764.aspx
      

  6.   


    看楼主的问题,我想楼主想问的并不是利用JSP去下载吧?
    是不是要这样:
    import java.net.*;
    import java.io.*;public class Main
    {
    public static void main(String[] args) {
    try
    {
    //要下载的文件的地址
    URL url = new URL("http://profile.csdn.net/joejoe1991/picture/1.jpg");
    URLConnection urlConn = url.openConnection();
    BufferedInputStream input = new BufferedInputStream(urlConn.getInputStream()); //c:/a.jpg 为保存的地址
    BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(new File("c:/a.jpg")));
    byte[] by = new byte[1024];

    int len = input.read(by);
    while (len >0)
    {
    output.write(by,0,len);
    len = input.read(by);
    } input.close();
    output.flush();
    output.close(); }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    }
      

  7.   

    2楼的大哥,人家说用IO流,多线程,网络编程实现下载,也就是socket,没说用jsp,要用jsp是个人就能写。
    渴望得分也不至于所问非所答啊,唉
    CSDN这是怎么了,唉