Java URL Load readURLText(String urlPath, String encoding)

Here you can find the source of readURLText(String urlPath, String encoding)

Description

read URL Text

License

Apache License

Declaration

public static String readURLText(String urlPath, String encoding) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.net.URL;

public class Main {

    public static String readURLText(String urlPath, String encoding) {
        BufferedReader br = null;
        try {/*from   w  ww . j a v  a  2s  .c  om*/
            URL url = new URL(urlPath);
            br = new BufferedReader(new InputStreamReader(url.openStream(), encoding));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}

Related

  1. readURLContents(String UrlText)
  2. readURLJSONArray(String urlString)
  3. readUrlProperties(URL url)
  4. readUrlStream(String urlString)
  5. readUrlText(final URL url, final String encoding)
  6. readUrlText(String urlString)
  7. readURLText(URL url, StringBuffer errorText)
  8. readURLThrowException(final String url)
  9. readURLToByteArray(URL url)