将输入流转为字符串

来源:互联网 发布:python pdf2htmlex 编辑:程序博客网 时间:2024/05/29 03:15

 

 

/**

* streamToString

* @param in

* @return

* @author XieYanZhou(Yan)

* @date 2011-4-14

* @version v1.0

*/

    private static String streamToString(InputStream in) {

        StringBuffer sb = new StringBuffer();

        BufferedReader br =

                new BufferedReader(new InputStreamReader(in));

        String strLine = "";

        try {

            while ((strLine = br.readLine()) != null) {

                sb.append(strLine.trim());

            }

        } catch (IOException e) {

            e.printStackTrace();

        }

        return sb.toString();

    }