Package COM. WSW. j2se. URL; import Java. io. bytearrayoutputstream; import Java. io. inputstream; import java.net. httpurlconnection; import java.net. URL; /*** obtain the source code of the website through the website domain name URL * @ author administrator **/public class htmlrequest {/*** // *** @ Param ARGs * @ throws malformedurlexception */public static void main (string [] ARGs) throws exception {URL url = new URL ("http://www.ifeng.com"); string urlsource = Geturlsource (URL); system. out. println (urlsource );} /*** // *** obtain the source code of the website through the website domain name URL * @ Param URL * @ return string * @ throws exception */public static string geturlsource (URL) throws exception {httpurlconnection conn = (httpurlconnection) URL. openconnection (); Conn. setrequestmethod ("get"); Conn. setconnecttimeout (5*1000); inputstream instream = Conn. getinputstream (); // get the HTML binary data byte [] D through the input stream ATA = readinputstream (instream); // converts binary data to byte bytes. String htmlsource = new string (data); Return htmlsource ;} /*** // *** convert binary data to byte array * @ Param instream * @ return byte [] * @ throws exception */public static byte [] readinputstream (inputstream instream) throws exception {bytearrayoutputstream outstream = new bytearrayoutputstream (); byte [] buffer = new byte [1204]; int Len = 0; while (LEN = I Nstream. Read (buffer ))! =-1) {outstream. Write (buffer, 0, Len) ;}instream. Close (); Return outstream. tobytearray ();}}