Here you can find the source of inputStream2String(InputStream inputStream)
public static String inputStream2String(InputStream inputStream) throws Exception
//package com.java2s; /**//from ww w. ja v a2 s .c om * Copyright (c) 2012 The Wiseserc. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static String inputStream2String(InputStream inputStream) throws Exception { if (inputStream == null) { return null; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int count = 0; while ((count = inputStream.read(buffer)) >= 0) { outputStream.write(buffer, 0, count); } String convertedBuffer = new String(outputStream.toByteArray()); outputStream.close(); return convertedBuffer; } }