Learn about Java networking Technology, here's a look at the URL,
To get content from the Internet,
You need to implement the following 4 steps,
1. Create a URL object that represents the network address of the resource,
2. Create a HttpURLConnection Connection object
3. Get content from the resulting Connection object getcontent ()
4. Output of the resulting content
Here's the code:
PackageCom.founder.sun;ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.InputStreamReader;Importjava.net.HttpURLConnection;Importjava.net.MalformedURLException;ImportJava.net.URL; Public classDemo04 { Public Static voidMain (string[] args)throwsIOException {//TODO auto-generated Method StubURL page =NewURL ("http://www.baidu.com"); HttpURLConnection Conn=(HttpURLConnection) page.openconnection (); InputStreamReader in=NewInputStreamReader ((InputStream) conn.getcontent ()); BufferedReader Buff=NewBufferedReader (in); String Line; Do{ Line=Buff.readline (); System.out.println (line); System.out.println ("/n"); } while(Line! =NULL); System.out.println ("OVER______________"); }}
The code is sent to Baidu to send a request back to the content of a return.
Can be compared with the source code of Baidu:
One of the Java Networking Technologies URL