Android InputStream to String Convert InputStreamTOStringUTF8(InputStream in)

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

Description

Input Stream TO String UTF

Declaration

public static String InputStreamTOStringUTF8(InputStream in) 

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 InputStreamTOStringUTF8(InputStream in) {
        return InputStreamTOString(in, "UTF-8");
    }/*from www.  ja  va  2 s .  co  m*/

    public static String InputStreamTOString(InputStream in, String encoding) {
        if (in == null) {
            return "";
        }
        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, String encoding)
  2. InputStreamTOString(InputStream in, String encoding)
  3. InputStreamTOString(InputStream in, String encoding)
  4. InputStreamTOString(InputStream in, String encoding)
  5. InputStreamTOString(InputStream in, String encoding)
  6. toString(InputStream is)
  7. toString(InputStream is)
  8. toString(InputStream is)
  9. toString(InputStream is)