Java InputStream to String inputStreamToString(InputStream in)

Here you can find the source of inputStreamToString(InputStream in)

Description

Reads the contents of an InputStream to a String .

License

LGPL

Parameter

Parameter Description
in the source InputStream .

Exception

Parameter Description
IOException an exception

Return

a with the contents of the .

Declaration

public static String inputStreamToString(InputStream in) throws IOException 

Method Source Code

//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();
    }
}

Related

  1. inputStreamToString(final InputStream stream)
  2. inputStreamToString(final InputStream stream, final String charset)
  3. inputStreamToString(InputStream in)
  4. inputStreamToString(InputStream in)
  5. InputStreamTOString(InputStream in)
  6. inputStreamToString(InputStream in)
  7. inputStreamToString(InputStream in)
  8. InputStreamToString(InputStream in)
  9. InputStreamTOString(InputStream in)