Java tutorial
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URLConnection; public class Main { private static String readAsString(URLConnection connection) throws IOException { InputStream inputStream = connection.getInputStream(); Reader reader = new InputStreamReader(inputStream, "UTF-8"); try { StringBuilder sb = new StringBuilder(); { char[] buffer = new char[2048]; while (true) { int read = reader.read(buffer); if (read < 0) break; sb.append(buffer, 0, read); } } return sb.toString(); } finally { try { reader.close(); } catch (IOException ignored) { } } } }