Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static String readData(InputStream inSream, String charsetName) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; while ((len = inSream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } byte[] data = outStream.toByteArray(); outStream.close(); inSream.close(); return new String(data, charsetName); } }