Android InputStream to String Convert streamToString(InputStream in, String charset)

Here you can find the source of streamToString(InputStream in, String charset)

Description

stream To String

Declaration

public static String streamToString(InputStream in, String charset) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class Main {
    public static String streamToString(InputStream in, String charset) {
        try {// w  ww . j a v  a 2s  .c om
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(in, charset));
            StringBuffer buffer = new StringBuffer();
            String line = null;
            try {
                while ((line = reader.readLine()) != null) {
                    buffer.append(line);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                reader.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return buffer.toString();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return "";
    }
}

Related

  1. readToString(final InputStream inputStream)
  2. inputStreamToString(InputStream inputstream)
  3. streamToString(InputStream is)
  4. inputStreamToString(InputStream is)
  5. inputStreamToString(InputStream stream)
  6. InputStreamToString(InputStream in)
  7. inputToString(InputStream inputStream, String encoding)
  8. converStreamToString(InputStream is)
  9. inputStreamToString(InputStream inputStream)