The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.net  [27 examples] > URLs  [8 examples]

e136. Getting Text from a URL

    try {
        // Create a URL for the desired page
        URL url = new URL("http://hostname:80/index.html");
    
        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {
            // str is one line of text; readLine() strips the newline character(s)
        }
        in.close();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }

 Related Examples
e132. Creating a URL
e133. Converting Between a URL and a URI
e134. Parsing a URL
e135. Sending a POST Request Using a URL
e137. Getting an Image from a URL
e138. Getting a Jar File Using a URL
e139. Accessing a Password-Protected URL

See also: Datagram    Encodings    HTTP    Hostnames and IP Addresses    Multicast    Sockets   


© 2002 Addison-Wesley.