From: http://hi.baidu.com/kh994354738/item/0795dae9eae94fc4bbf37d5f
Package COM. pickedpoint. sois. test. action; import Java. io. *; import java.net. *; public class testurl {/*** download Remote File * @ Param photourl file path * @ Param filename download to local path * @ return success */Public Boolean saveurlas (string photourl, string filename) {try {URL url = new URL (photourl); httpurlconnection connection = (httpurlconnection) URL. openconnection (); datainputstream in = new datainputstream (connection. Getinputstream (); dataoutputstream out = new dataoutputstream (New fileoutputstream (filename); byte [] buffer = new byte [4096]; int COUNT = 0; while (COUNT = in. read (buffer)> 0) {out. write (buffer, 0, count);} Out. close (); In. close (); Return true;} catch (exception e) {system. out. println (E); Return false ;}/ *** obtain the remote file content (compatible with HTTP and FTP) * @ Param urlstring file path * @ return file content */Public String Getdocumentat (string urlstring) {stringbuffer document = new stringbuffer (); try {URL url = new URL (urlstring); urlconnection conn = URL. openconnection (); bufferedreader reader = new bufferedreader (New inputstreamreader (Conn. getinputstream (), "UTF-8"); string line = NULL; while (line = reader. readline ())! = NULL) {document. append (LINE + "\ n");} reader. close ();} catch (malformedurlexception e) {system. out. println ("unable to connect to URL:" + urlstring);} catch (ioexception e) {system. out. println ("ioexception when connecting to URL:" + urlstring);} return document. tostring ();}/***** @ Param ARGs */public static void main (string [] ARGs) {testurl test = new testurl (); string photourl = "HT TP: // service.pickedpoint.com/pointpublisher/gx_service.xml "; string filename = photourl. substring (photourl. lastindexof ("/"); string filepath = "/home/developer/soft/Apache-Tomcat-6.0.32/webapps/soisweb2/isystems/pointpublisher/resource"; system. out. println (test. getdocumentat (photourl); // Boolean flag = test. saveurlas (photourl, filepath + filename); // system. out. println ("Run OK! \ N get URL File "+ flag );}}