Java URL Download get(URL url)

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

Description

get

License

Open Source License

Declaration

public static String get(URL url) throws IOException 

Method Source Code

//package com.java2s;
/*//ww  w. ja v a2 s. c  o  m
 * Copyright ? 2014 - 2016 | Wurst-Imperium | All rights reserved.
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import java.io.BufferedReader;

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

import java.net.HttpURLConnection;

import java.net.URL;

public class Main {
    public static String get(URL url) throws IOException {
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        StringBuilder buffer = new StringBuilder();
        for (String line; (line = input.readLine()) != null;) {
            buffer.append(line);
            buffer.append("\n");
        }
        input.close();
        return buffer.toString();
    }
}

Related

  1. get(String url, Map params)
  2. get(String url, String encoding)
  3. get(String urlStr)
  4. get(String urlString)
  5. get(URL host, String endpoint, String customer, String name, String version, OutputStream out)
  6. get(URL url, String acceptType)