java IO流上传,下载文件。好好看看。

解决方案 »

  1.   

    HttpURLConnection urlConn = null;
                    
                            url = new URL(strUrl);
                            urlConn = (HttpURLConnection) url.openConnection();
                            urlConn.setConnectTimeout(1000 * 20);
                           InputStreamReader in = new InputStreamReader(urlConn.getInputStream());
    获取到inputstream,你就写到你的文件夹下去
                            
      

  2.   

    String filePath=request.getRealPath("/..");
       String filename = "total.zip";
           File fileLoad = new File(filePath, filename);         FileInputStream in = null; // 输入流  
           OutputStream out = response.getOutputStream();  
           byte b[] = new byte[1024];  
      
            try {  
     
                 response.setContentType("application/x-msdownload;");  
      
                response.setHeader("Content-disposition", "attachment; filename="  
                       + new String(filename.getBytes("UTF-8"), "UTF-8"));  
      
                // download the file.  
                in = new FileInputStream(fileLoad);  
               int n = 0;  
                while ((n = in.read(b)) != -1) {  
                    out.write(b, 0, n);  
               }         } catch (Throwable e) {  
                e.printStackTrace();  
          } finally {  
               try {  
                   in.close();  
                out.close();  
                        } catch (Throwable e) {  
                    e.printStackTrace();  
               }  
           }