Java URL Download downloadAsString(String url)

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

Description

download As String

License

Open Source License

Declaration

public static String downloadAsString(String url) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

public class Main {
    public static String downloadAsString(String url) throws IOException {
        try (InputStream is = new URL(url).openStream();
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr)) {
            StringBuilder sb = new StringBuilder();
            String line;/*w  w  w  .j a  va2  s.  c  o  m*/
            while ((line = br.readLine()) != null) {
                sb.append(line).append('\n');
            }

            return sb.toString();
        }
    }
}

Related

  1. download(URL url, File destination)
  2. download(URL url, File file)
  3. downloadAndExtract(String fileURL, String targetDirectory)
  4. downloadAndSaveImage(URL imageUrl, String path)
  5. downloadAndUnzip(String url, File location)
  6. downloadBinary(URL BaseURL, String Name, File TargetDirectory)
  7. downloadData(String url, String params)
  8. downloadDirectory(URL dirUrl, File destDir)
  9. downloadFile(File parent, String prefix, String suffix, URL url)