Java访问Url地址并下载文件

java

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();   

     }

}

}

以上是 Java访问Url地址并下载文件 的全部内容, 来源链接: utcz.com/z/393644.html

回到顶部