Android InputStream to String Convert InputStreamTOString(InputStream in, String encoding)

Here you can find the source of InputStreamTOString(InputStream in, String encoding)

Description

Input Stream TO String

Declaration

public static String InputStreamTOString(InputStream in, String encoding) 

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 {

    public static String InputStreamTOString(InputStream in, String encoding) {
        if (in == null) {
            return "";
        }/* w  ww . ja  v a  2 s  .  co  m*/
        try {
            StringBuilder sb = new StringBuilder();
            String line;
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(in, encoding));
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            return sb.toString();
        } catch (Exception e) {
            return "";
        } finally {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
    }
}

Related

  1. InputStreamTOString(InputStream in)
  2. InputStreamTOString(InputStream in)
  3. InputStreamTOString(InputStream in)
  4. InputStreamTOString(InputStream in)
  5. InputStreamTOString(InputStream in)
  6. InputStreamTOString(InputStream in, String encoding)
  7. InputStreamTOString(InputStream in, String encoding)
  8. InputStreamTOString(InputStream in, String encoding)
  9. InputStreamTOString(InputStream in, String encoding)