Java URL Download fetchURLContents(String url)

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

Description

fetch URL Contents

License

Open Source License

Declaration

public static String fetchURLContents(String url) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.IOException;

import java.io.InputStreamReader;

import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static String fetchURLContents(String url) {
        URL u;//from   w ww . java 2 s .c  om
        try {
            u = new URL(url);
            HttpURLConnection uc = (HttpURLConnection) u.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
            String s;
            uc.setConnectTimeout(1000);
            uc.setReadTimeout(1000);
            in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
            String ret = new String();
            while ((s = in.readLine()) != null) {
                if (ret.length() > 0)
                    ret += "\n";
                ret += s;
            }
            return (ret);
        } catch (ConnectException ex) {
            //System.out.println("Connect exception");
        } catch (MalformedURLException ex) {
        } catch (IOException ex) {
        } catch (Exception ex) {
        }
        return (null);
    }
}

Related

  1. fetchURL(String url_string)
  2. fetchURL(String urlStr, List errors, Map requestProperties)
  3. fetchUrl(URL url)
  4. fetchUrl(URL url)
  5. fetchURL(URL url)
  6. get(String url)
  7. get(String url)
  8. get(String url)
  9. get(String url)