集册 Java实例教程 通过BufferedReader读取输入Stream To String

通过BufferedReader读取输入Stream To String

欢马劈雪     最近更新时间:2020-01-02 10:19:05

626
通过BufferedReader读取输入Stream To String

/**来自 
 时 代 J a v a**/

import org.apache.log4j.Logger;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.Collection;


public class Main{

    private final static Logger log = Logger.getLogger(StringUtil.class);

    public static String inputStreamToString(final InputStream inputStream) {


        final BufferedReader br = new BufferedReader(new InputStreamReader(

                inputStream));

        final StringBuilder sb = new StringBuilder();
//来 自 nowjava.com - 时  代  Java

        try {

            while (br.ready()) {

                sb.append(br.readLine());

            }

        } catch (IOException e) {

            log.error("can't read line from buffered reader", e);

        } finally {

            
展开阅读全文