Android InputStream to String Convert getStringFromInputStream(InputStream is)

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

Description

Converts inputStream into String

Parameter

Parameter Description
is inputString

Return

converted string

Declaration

public static String getStringFromInputStream(InputStream is) 

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 {
    /**/*w w  w . ja v a2 s  .  c om*/
     * Converts inputStream into String
     * 
     * @param is
     *            inputString
     * @return converted string
     */
    public static String getStringFromInputStream(InputStream is) {

        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();

        String line;
        try {

            br = new BufferedReader(new InputStreamReader(is));
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return sb.toString();
    }
}

Related

  1. convertStreamToString(InputStream is)
  2. convertStreamToString(java.io.InputStream is)
  3. convertStreamToString(java.io.InputStream is)
  4. streamToString(InputStream is)
  5. stringFromInputStream(InputStream is)