Through the URL package provided by Java, we can download the webpage from the specified website like the IE browser, and the download is definitely the real HTML, with this principle, we can make our own kernel browser!
Please refer to the following source code for implementation principles:
Import java.net. url;
Import java.net. urlconnection;
Import java. Io. ioexception;
Import java. util. date;
Public class urlc
{
Void display ()
{
Byte Buf [] = new byte [100];
Try
{
System. Out. Print ("Enter the URL of the file :");
// Read the URL entered by the user
Int ount = system. In. Read (BUF );
String ADDR = New String
(BUF, 0, count );
// Pass the URL string entered by the user into the URL Class Object
URL url = new URL (ADDR );
// Create a urlconnection object. Use the openconnection method of the URL to return the connection to the object of urlconnection.
// The actual URL's openconnection return value is a urlconnection
Urlconnection c = URL. openconnection ();
// Use the connect () method of urlconnection to establish a connection
C. Connect ();
// Display information about the connection. These are the urlconnection methods.
System. Out. println ("content type:" + C. getcontenttype ());
System. Out. println ("Content Encoding:" + C. getcontentencoding ());
System. Out. println ("Content Length:" + C. getcontentlength ());
System. Out. println ("creation date:" + new date (C. getdate ()));
System. Out. println ("Last modified Date:" + new date (C. getlastmodified ()));
System. Out. println ("End Date:" + new date (C. getexpiration ()));
}
Catch (ioexception E)
{
System. Out. println (E );
}
}
Public static void main (string [] ARGs)
{
Urlc APP = new urlc ();
App. Display ();
}
}