Use the URL class package provided by Java to read the online file

xiaoxiao2021-03-06  71

With the URL package provided by Java, we can download the web from the specified URL as the IE browser, and the download is definitely true HTML, using this principle we can make your own kernel browser!

Please see this is the source program for implementation:

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 ("Please enter the URL address of the file:");

/ / Read URL input by the user

Int out = system.in.read (buf);

String addr = new string

(BUF, 0, count);

// Transfer the URL string of the user into the URL class object

URL URL = New URL (ADDR);

// Create a URLCONNECTION object, return the connection to the URLConnection object with the URL's OpenConnection method.

/ / The return value of the OpenConnection of the URL is the URLConnection.

UrlConnection C = url.openConnection ();

// Establish a connection with the URLConnection's connection () method

C.Connect ();

/ / Display information about the connection, these are the method of urlConnection

System.out.println ("Content Type:" C.GetContentType ());

System.out.println ("Content Code:" C.GetContenTencoding ());

System.out.println ("Content Length:" C.GetContentLength ());

System.out.println ("Create Date:" New Date (C.Getdate ())));

System.out.println ("Last Modified Date:" New Date (C.GetlastModified ()));

System.out.println ("Termination Date:" New Date (C.GETEXPIRATION ()));

}

Catch (IOException E)

{

System.out.println (e);

}

}

Public static void main (string [] args)

{

URLC App = New URLC ();

app.display ();

}

}

转载请注明原文地址:https://www.9cbs.com/read-94041.html

New Post(0)