首页 > 其他 > 详细

将InputStream 转换成 String

时间:2014-08-28 17:05:21      阅读:283      评论:0      收藏:0      [点我收藏+]
public static String InputStream2String(InputStream in, String encoding)  {
	    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
	    
	    byte[] data = new byte[4096];
	    int count = -1;
	    try {
        while((count=in.read(data, 0, 4096)) != -1) {
          outStream.write(data, 0, count);
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
	    data = null;
	    String str = null;
	    try {
        str = new String(outStream.toByteArray(), encoding);
        
      } catch (IOException e) {
        e.printStackTrace();
      }

	  return str;
	  }


将InputStream 转换成 String

原文:http://my.oschina.net/u/923087/blog/307638

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!