Package download; import Java. io. file; import Java. io. fileoutputstream; import Java. io. inputstream; import Java. io. outputstream; import java.net. URL; import java.net. urlconnection; import java.util.zip. gzipinputstream;/*** download an object from the address specified by the URL to the local device * 17:28:50 **/public class downloader {Private URL; // URL of the network file urlconnection con; // connection to the URL inputstream is; // input stream public downloader (string urlstr, string Path, string filename) throws exception {url = new URL (urlstr); con = URL. openconnection (); is = con. getinputstream (); // The file int length = con. getcontentlength (); If (length = 71495) {Throw new exception (urlstr + "indicates that the object does not exist. ");} file folder = new file (PATH); If (folder. exists () = false | folder. isfile () {folder. mkdir ();} string filename = path + file. separator + filename; string code = con. getheaderfield ("Co Ntent-encoding "); If (null! = Code) & code. equals ("gzip") {gzipinputstream GIS = new gzipinputstream (is); // 1 k Data Buffer byte [] BS = new byte [1024]; // read the data length int Len; // output file stream outputstream OS = new fileoutputstream (filename); // start reading while (LEN = GIS. read (BS ))! =-1) {OS. write (BS, 0, Len);} // complete. Close all links to GIS. close (); OS. close (); is. close ();} else {// 1 k Data Buffer byte [] BS = new byte [1024]; // read Data Length int Len; // output file stream outputstream OS = new fileoutputstream (filename); // start reading while (LEN = is. read (BS ))! =-1) {OS. write (BS, 0, Len);} // complete. Close all connected OS. close (); is. close ();} system. out. println (filename + "saved");} public static void main (string [] ARGs) throws exception {New downloader ("http:// B .bst.126.net/newpage/style/nblog/4007/img/top_banner.jpg", "C: // wallpaper // 2 "," top_banner.jpg ");}}