Java URL Download fetchURL(String url)

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

Description

fetch URL

License

Open Source License

Declaration

public static String fetchURL(String url) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Gabriel Skantze./*w  w  w .j a va2  s  .  c  o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Gabriel Skantze - initial API and implementation
 ******************************************************************************/

import java.net.URL;
import java.net.URLConnection;

import java.util.Scanner;

public class Main {
    public static String fetchURL(String url) {
        String content = null;
        URLConnection connection = null;
        try {
            connection = new URL(url).openConnection();
            Scanner scanner = new Scanner(connection.getInputStream());
            scanner.useDelimiter("\\Z");
            content = scanner.next();
            return content;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }
}

Related

  1. downloadZip(URL file, File dump)
  2. downlod(String url, File dest)
  3. downNetImg(String filePath, String remotePath, String htmlUrl, String fileName)
  4. downPicture(String filePath, String imageUrl, String fileName)
  5. fetchUrl(String _url, String charset)
  6. fetchURL(String url_string)
  7. fetchURL(String urlStr, List errors, Map requestProperties)
  8. fetchUrl(URL url)
  9. fetchUrl(URL url)