Java URL Download downloadText(String url)

Here you can find the source of downloadText(String url)

Description

Download text from a string url.

License

Open Source License

Parameter

Parameter Description
url The url to download from.

Exception

Parameter Description
IOException an exception

Return

The text from the webpage.

Declaration

public static String downloadText(String url) throws IOException 

Method Source Code

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

import java.io.IOException;

import java.net.URL;
import java.util.Scanner;

public class Main {
    /**/*  w w w  .j a  va2s.  c  om*/
     * Download text from a string url.
     *
     * @param url The url to download from.
     * @return The text from the webpage.
     * @throws IOException
     */
    public static String downloadText(String url) throws IOException {
        return downloadText(new URL(url));
    }

    /**
     * Download text from a {@link URL}.
     *
     * @param url The url to download from.
     * @return The text from the webpage.
     * @throws IOException
     */
    public static String downloadText(URL url) throws IOException {
        return new Scanner(url.openStream()).useDelimiter("\\A").next();
    }
}

Related

  1. downloadPageSource(String stringURL)
  2. downloadSource(PrintStream out, PrintStream err, String srcURL, String dirStr, boolean extract)
  3. downloadString(String url)
  4. downloadString(URL url)
  5. downloadString(URL url)
  6. downloadTextFromUrl(String url)
  7. downloadTo(String url, String filename)
  8. downloadToDirectory(URL url, String directoryName)
  9. downloadToFile(String url, File file)