Java URL Load readTextFromUrl(URL url)

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

Description

Return the text of the file with the given URL.

License

Open Source License

Parameter

Parameter Description
url The URL.

Return

The contents of the file.

Declaration

public static String readTextFromUrl(URL url) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.URL;

public class Main {
    /**// ww  w . java 2 s.co m
     * Return the text of the file with the given URL. E.g. if
     * http://test.be/text.txt is given the contents of text.txt is returned.
     * 
     * @param url
     *            The URL.
     * @return The contents of the file.
     */
    public static String readTextFromUrl(URL url) {
        StringBuffer fubber = new StringBuffer();
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                fubber.append(inputLine).append("\n");
            }
            in.close();
        } catch (IOException exception) {
            exception.printStackTrace();
        }
        return fubber.toString();
    }
}

Related

  1. readStringFromURL(URL url)
  2. readText(final URL url)
  3. readText(final URL url)
  4. readTextFile(final URL resource)
  5. readTextFileAtUrl(final URL url)
  6. readTextStream(URL url, String encoding)
  7. readTextURL(URL url)
  8. readURL(final URL fileURL)
  9. readUrl(final URL url)