Created
December 25, 2013 05:03
-
-
Save Keda87/8120319 to your computer and use it in GitHub Desktop.
GET data from internet / api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.net.URLConnection; | |
public class JSONParser { | |
public static String getPlainJSON(String api) throws MalformedURLException, IOException { | |
URL url = new URL(api); | |
URLConnection urlc = url.openConnection(); | |
StringBuilder builder; | |
try (InputStreamReader inStream = new InputStreamReader(urlc.getInputStream()); BufferedReader buff = new BufferedReader(inStream)) { | |
builder = new StringBuilder(); | |
while (true) { | |
String nextLine = buff.readLine(); | |
String NL = System.getProperty("line.separator"); | |
if (nextLine != null) { | |
builder.append(nextLine).append(NL); | |
} else { | |
break; | |
} | |
} | |
} | |
return builder.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment