Java tutorial
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class Main { public static String readIt(InputStream stream, int maxLen) throws IOException { Reader reader = null; reader = new InputStreamReader(stream, "UTF-8"); char[] buffer = new char[maxLen]; Integer num = reader.read(buffer); String response = new String(buffer); if (num < 0) num = 0; return response.substring(0, num); } }