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

将InputStream 转换成 String

时间:2014-08-28 17:05:21      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:java   io   ar   sp   on   new   ad   c   as   

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

标签:java   io   ar   sp   on   new   ad   c   as   

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

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