Java URL Load readStringFromUrl(URL url)

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

Description

Reads content from specified URL

License

Open Source License

Parameter

Parameter Description
url a parameter

Exception

Parameter Description
IOException an exception

Return

Read content as string.

Declaration

public static String readStringFromUrl(URL url) throws IOException 

Method Source Code

//package com.java2s;

import java.io.*;

import java.net.URL;

public class Main {
    /**//from   www.j a  va2s  .c  o  m
     * Reads content from specified URL
     * @param url
     * @throws IOException
     * @return Read content as string.
     */
    public static String readStringFromUrl(URL url) throws IOException {
        StringBuffer buffer = new StringBuffer();
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        int ch;
        while ((ch = in.read()) != -1) {
            buffer.append((char) ch);
        }
        in.close();

        return buffer.toString();
    }
}

Related

  1. readResource(final URL filename)
  2. readResource(URL resource)
  3. readServicesFromUrl(Collection list, URL url)
  4. readSqlStatements(URL url)
  5. readStopwordsURL(URL url, boolean lowercase)
  6. readStringFromURL(URL url)
  7. readText(final URL url)
  8. readText(final URL url)
  9. readTextFile(final URL resource)