Java InputStream to String inputStreamToString(InputStream in)

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

Description

read a String from an InputStream object.

License

Apache License

Parameter

Parameter Description
in InputStream

Exception

Parameter Description
Exception an exception

Return

String

Declaration

public static String inputStreamToString(InputStream in) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    /**//from   w ww  .  ja  v  a 2 s .  co m
     * read a String from an InputStream object.
     * @param in InputStream
     * @return String
     * @throws Exception
     */
    public static String inputStreamToString(InputStream in) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        StringBuffer buffer = new StringBuffer();
        String line = "";
        while ((line = br.readLine()) != null) {
            buffer.append(line);
        }
        return buffer.toString();
    }
}

Related

  1. inputStreamToString(final InputStream in)
  2. inputStreamToString(final InputStream inputStream, final String... optionalCharsetName)
  3. inputStreamToString(final InputStream is, final int bufferSize)
  4. inputStreamToString(final InputStream stream)
  5. inputStreamToString(final InputStream stream, final String charset)
  6. inputStreamToString(InputStream in)
  7. InputStreamTOString(InputStream in)
  8. inputStreamToString(InputStream in)
  9. inputStreamToString(InputStream in)