Here you can find the source of getJsonFromUrl(String url)
public static String getJsonFromUrl(String url) throws IOException
//package com.java2s; //License from project: Open Source License 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 getJsonFromUrl(String url) throws IOException { URL urll = new URL(url); HttpURLConnection conn = (HttpURLConnection) urll.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); }//from w w w .ja v a 2 s .c o m BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; StringBuilder stringa = new StringBuilder(); while ((output = br.readLine()) != null) { stringa.append(output); } conn.disconnect(); return stringa.toString(); } }