请问几个问题: 
1。用Socket实现ftp和http的下载,用 
  Socket s; 
  //init Socket there 
  BufferedReader reader = new BufferedReader( 
      new InputStreamReader(s.getInputStream()) 
  ); 
  从reader中读取Http的head(需要用到readLine())然后怎么样通过stream读入数据。继续用reader读可以吗? 2。用URL、URLConnection、HttpURLConnection怎么实现Http、和Ftp下载,我需要对其有更多的控制,比如说断点续传,怎么构造自己的FtpURLConnection; 3。有没有对java.net.*包中的设计模式介绍/详述的资料。

解决方案 »

  1.   

    试试这个看?String sr = request.getParameter("url");
     String filepro = sr.substring( (sr.length()-3) );
           response.setContentType( "application/" + filepro ); // MIME type for pdf doc 
           response.setHeader("Content-disposition",
                     "attachment; filename=" + "my.doc");
          String fileURL = sr;
          URL  url=new URL(fileURL);
          BufferedInputStream bis = new BufferedInputStream(url.openStream());
          BufferedOutputStream bos = new BufferedOutputStream( response.getOutputStream()); 
          byte[] buff = new byte[2048];
          int bytesRead;
          while (-1!=(bytesRead=(bis.read(buff,0,buff.length)))){
              bos.write(buff,0,bytesRead); 
          }
          if (bis!=null){
            bis.close();
          }
          if (bos!=null){
             bos.close();
         }
      

  2.   

    据传说,好像sun有一个ftp什么的package的,怎么不去找找看呢?
      

  3.   

    在ftp客户端程序中,好像可以在接收数据之前发命令给服务器,说明从文件的哪个位置开始接收。网上有些断点续传的代码,可以参考
      

  4.   

    那http的怎么办呢,有什么确切的资料么?