Common methods in the 1.URL class:
Create a URL object
url url = new URL ("http://www.baidu.com");
URL url1 = new URL (url, "/index.html?usrname=lqq#test");
Common methods for URLs
System.out.println ("URL host name:" +url1.gethost ());
System.out.println ("URL protocol:" +url1.getprotocol ());
System.out.println ("URL port:" +url1.getport ());
System.out.println ("URL file path:" +url1.getpath ());
System.out.println ("URL query string:" +url1.getquery ());
System.out.println ("url relative path:" +url1.getref ());
SYSTEM.OUT.PRINTLN ("URL filename:" +url1.getfile ());
2. Get HTML file content via URL:
//create a URL instance url url = new URL ("http://www.baidu.com");
Gets a InputStream object InputStream is = Url.openstream () through the OpenStream method of the URL object;
InputStreamReader ISR = new InputStreamReader (IS, "utf-8");
BufferedReader br = new BufferedReader (ISR);
FILE BD = new file (".../baidu.html");
PrintWriter pw = new PrintWriter (BD);
Reads String s = Br.readline () by row;
while (S!=null) {pw.print (s);
Pw.flush ();
S=br.readline ();
//Close Related resources pw.close ();
Br.close ();
Isr.close ();
Is.close ();