Here you can find the source of urlContents(String urlString)
public static String urlContents(String urlString)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; public class Main { public static String urlContents(String urlString) { try {//from www . j av a2s.co m URL url = new URL(urlString); URLConnection connection = url.openConnection(); // following needed? // connection.setRequestProperty("User-Agent", ???); connection.setConnectTimeout(30000); connection.setReadTimeout(30000); return bufferedReaderToString(new BufferedReader(new InputStreamReader(connection.getInputStream()))); } catch (Exception e) { e.printStackTrace(); return null; } } private static String bufferedReaderToString(BufferedReader in) throws IOException { StringBuilder contents = new StringBuilder(); String line; while ((line = in.readLine()) != null) { contents.append(line + "\r"); } in.close(); return contents.toString(); } }