Java HTTP Read getContentAsString(URL url)

Here you can find the source of getContentAsString(URL url)

Description

get Content As String

License

Open Source License

Declaration

public static String getContentAsString(URL url) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static String getContentAsString(URL url) throws IOException {
        URLConnection conn = url.openConnection();
        conn.connect();//from  w w w  .  j ava 2s . c o  m
        InputStream in = conn.getInputStream();
        Reader r = new InputStreamReader(in, "UTF-8");
        int c;
        StringBuffer buf = new StringBuffer();
        while ((c = r.read()) != -1) {
            buf.append((char) c);
        }
        return buf.toString();
    }
}

Related

  1. getByteaArrayFromConn(HttpURLConnection conn, boolean isSuccess)
  2. getContent(final HttpURLConnection con)
  3. getContent(final String urlString)
  4. getContent(String urlStr)
  5. getContentEncoding(URL url)
  6. getContentFromHttpGetBasicAuth(String urlString, String username, String password)
  7. getContentFromURL(String sURL)
  8. getContentFromURL(String url)