Here you can find the source of readTextStream(URL url, String encoding)
public static String readTextStream(URL url, String encoding) throws IOException
//package com.java2s; /*/* w ww .java 2s . co m*/ * This file is part of the Jose Project * see http://jose-chess.sourceforge.net/ * (c) 2002-2006 Peter Sch?fer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * */ import java.io.*; import java.net.URL; public class Main { /** * read a text from a URL */ public static String readTextStream(URL url, String encoding) throws IOException { InputStream in = url.openStream(); return readTextStream(in, encoding); } /** * read a text input stream */ public static String readTextStream(InputStream input, String encoding) throws IOException { InputStreamReader in = new InputStreamReader(input, encoding); StringWriter out = new StringWriter(); copyReader(in, out); in.close(); out.close(); return out.toString(); } /** * copies the contens of a stream */ public static void copyReader(Reader in, Writer out) throws IOException { char[] buffer = new char[4096]; for (;;) { int count = in.read(buffer, 0, 4096); if (count < 0) break; out.write(buffer, 0, count); } } }