Java訪問Url地址並下載文件


package com.yangjuqi.resource;

import java.io.*;

import java.net.URL;

/** * java訪問URL並下載文件 * @author yangjuqi 2007-12-14 下午04:08:51 * */

public class ResourceURLServer

{

  public static void getURLResource(String ourputFile,String urlStr) throws Exception

{   

      FileWriter fw = new FileWriter(ourputFile);   

      PrintWriter pw = new PrintWriter(fw);   

      URL resourceUrl = new URL(urlStr);   

      InputStream content = (InputStream) resourceUrl.getContent();   

      BufferedReader in = new BufferedReader(new InputStreamReader(content));   

      String line;   

      while ((line = in.readLine()) != null)

    {    

        pw.println(line);   

    }   

       pw.close();   

       fw.close();

}

public static void main(String[] args)

{   

      try

     {    

            System.out.println("begin");    

            getURLResource("f:\\測試.xls","http://localhost:8088/bgcl/bussi/ticketQuery.jsp?excel=excel");    

            System.out.println("end");   

}

       catch (Exception e)

     {    

           e.printStackTrace();   

     }

}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM