码迷,mamicode.com
首页 > 其他好文 > 详细

输入流转换成字符串

时间:2015-08-19 00:31:49      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

    /**
     * 输入流转换成字符串
     * @param is
     * @param destCode
     * @return
     * @throws IOException
     */
    public static String readFromStream(InputStream is,String destCode) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        
        byte[] buffer = new byte[1024];
        
        int len = 0;
        
        while ((len = is.read(buffer)) != -1) {
            baos.write(buffer, 0, len);
        }
        
        is.close();
        
        String result = baos.toString(destCode);
        
        baos.close();
        
        return result;
    }

 

输入流转换成字符串

标签:

原文地址:http://www.cnblogs.com/cbooy/p/4741040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!