Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class Main { public static String textToString(Reader xquery) throws IOException { StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(xquery); String NL = System.getProperty("line.separator"); String line = null; try { while ((line = br.readLine()) != null) { sb.append(line).append(NL); } sb.deleteCharAt(sb.length() - 1); } finally { br.close(); } return sb.toString(); } public static String textToString(InputStream stream) throws IOException { Reader r = new InputStreamReader(stream); return textToString(r); } }