Java URL Load readTextURL(URL url)

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

Description

read Text URL

License

Open Source License

Declaration

public static String readTextURL(URL url) 

Method Source Code

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

import java.io.InputStream;

import java.net.URL;

import java.util.Scanner;

public class Main {
    public static String readTextURL(URL url) {
        try {/*from   w ww  . ja va  2s. c  o m*/
            return readText(url.openStream());
        } catch (Exception e) {
            throw new RuntimeException("Reading from URL \"" + url + "\" failed", e);
        }
    }

    public static String readText(InputStream in) {
        StringBuilder text = new StringBuilder();
        Scanner scanner = new Scanner(in);
        while (scanner.hasNextLine()) {
            text.append(scanner.nextLine() + "\n");
        }
        return text.toString();
    }
}

Related

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