Java InputStream to String inputStream2String(InputStream in)

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

Description

input Stream String

License

Apache License

Declaration

public static String inputStream2String(InputStream in) throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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 inputStream2String(InputStream in) throws UnsupportedEncodingException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
        StringBuffer sb = new StringBuffer();
        String line = null;/*from  www.j a  v a2  s . com*/
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }
}

Related

  1. getStreamContent(InputStream is)
  2. getStreamContent(InputStream stream, int bufferSize)
  3. getStreamContentAsString(InputStream is)
  4. getStreamContentAsString(InputStream is, String encoding)
  5. getStreamContents(final InputStream is)
  6. inputStream2String(InputStream in)
  7. inputStream2String(InputStream in)
  8. InputStream2String(InputStream in, String encoding)
  9. InputStream2String(InputStream in_st, String charset)