Here you can find the source of inputStreamToString(InputStream in)
Parameter | Description |
---|---|
in | the source InputStream . |
Parameter | Description |
---|---|
IOException | an exception |
public static String inputStreamToString(InputStream in) throws IOException
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.io.InputStream; public class Main { /**/* www .j a va 2 s . co m*/ * Reads the contents of an {@link InputStream} to a {@link String}. * * @param in * the source {@link InputStream}. * * @return a {@link String} with the contents of the {@link InputStream}. * * @throws IOException */ public static String inputStreamToString(InputStream in) throws IOException { StringBuffer out = new StringBuffer(); byte[] b = new byte[4096]; for (int n; (n = in.read(b)) != -1;) { out.append(new String(b, 0, n)); } return out.toString(); } }