One of the Java Networking Technologies URL

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.