Package COM. haier. adthird. util; import Java. io. fileoutputstream; import Java. io. inputstream; import Java. io. outputstream; import java.net. httpurlconnection; import java.net. URL; public class gputil {/*** read stream to disk ** @ Param inputstream * @ Param filepath * @ throws exception */public static void readstreamtodisk (inputstream, string filepath) throws exception {byte [] BS = new byte [1024*2]; Int Len; outputstream OS = new fileoutputstream (filepath); While (LEN = inputstream. Read (BS ))! =-1) {OS. write (BS, 0, Len);} OS. close (); inputstream. close ();}/*** get the connection by reading the URL ** @ Param URL * @ return * @ throws exception */public static httpurlconnection readurl (string URL) throws exception {URL picurl = new URL (URL); httpurlconnection = (httpurlconnection) picurl. openconnection (); httpurlconnection. setconnecttimeout (3000); httpurlconnection. setdoinput (true); // get the data from the server return httpurlconnection;}/*** get the connection by reading the URL (input stream) ** @ Param URL * @ return * @ throws exception */public static inputstream readurl_inputstream (string URL) throws exception {httpurlconnection = readurl (URL); Return httpurlconnection. getinputstream ();}}
Gao Peng Tool