Android InputStream to String Convert convertStreamToString(InputStream is)

Here you can find the source of convertStreamToString(InputStream is)

Description

Convert an InputStream to String

Parameter

Parameter Description
is the given InputStrem

Exception

Parameter Description
IOException if operation fails

Return

a String

Declaration

public static String convertStreamToString(InputStream is)
        throws IOException 

Method Source Code

//package com.java2s;

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    /**/*from  ww w.j  a  v  a2s.  c  o m*/
     * Convert an InputStream to String
     * 
     * @param is
     *            the given InputStrem
     * @return a String
     * @throws IOException
     *             if operation fails
     */
    public static String convertStreamToString(InputStream is)
            throws IOException {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line).append("\n");
        }
        reader.close();
        return sb.toString();
    }
}

Related

  1. inputToString(InputStream inputStream, String encoding)
  2. converStreamToString(InputStream is)
  3. inputStreamToString(InputStream inputStream)
  4. streamToString(InputStream is)
  5. slurp(InputStream in)
  6. inStream2Str(InputStream inputStream, String encode)
  7. readIt(InputStream stream)
  8. inputStream2String(InputStream inputStream)
  9. InputStreamTOString(InputStream in)