解析字符串

解析字符串:
封装一个解析字符串的工具类,方便调用

public static String readStream(InputStream is){
  try{
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       int len = 0;
       byte[] buffer = new byte[1024];
       while((len = is.read(buffer))!=-1){
          baos.write(buffer,0,len);
       }
     is.close();
     bos.close();
     byte[] result = baos.toByteArray();
     String temp = new String(result);
    return temp;
   }cath(IOException e){
     e.printStackTrace();
    return"获取失败";

   }
}

posted @ 2016-06-29 11:40  空城少年亦暖心  阅读(56)  评论(0编辑  收藏  举报