Java URL Connection getPage(String url)

Here you can find the source of getPage(String url)

Description

get Page

License

MIT License

Declaration

public static String getPage(String url) 

Method Source Code

//package com.java2s;
/**/*w w  w .j  a  v  a 2 s  .c o m*/
 * This software is licensed under the MIT license.
 * If you wish to modify this software please give credit and link to the git: https://github.com/Moudoux/OTIRC.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static String getPage(String url) {
        String result = "";
        try {

            URL url1 = new URL(url);
            URLConnection urlConn = url1.openConnection();

            BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

            String text;

            while ((text = in.readLine()) != null) {
                result = result + text;
            }

            in.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related

  1. getLastModified(URLConnection connection)
  2. getLength(String htmlUrl)
  3. getLines(final URL url, final int linesToRead)
  4. getOutputStream(final URL outputURL)
  5. getOutputStream(URL url)
  6. getPageContent(String inputUrlString)
  7. getRealURL(URL url)
  8. getRemoteTimestamp(final String url)
  9. getRequest(URLConnection conn)