将一个InputStream流转换成字符串

 /**
    * 将一个InputStream流转换成字符串
    *
    * @param is
    * @return
    */
   public static String toConvertString(InputStream is) {
       StringBuffer res = new StringBuffer();
       InputStreamReader isr = new InputStreamReader(is);
       BufferedReader read = new BufferedReader(isr);
       try {
           String line;
           line = read.readLine();
           while (line != null) {
               res.append(line + "
");
               line = read.readLine();
           }
       } catch (IOException e) {
           e.printStackTrace();
       } finally {
           try {
               if (null != isr) {
                   isr.close();
                   isr.close();
               }
               if (null != read) {
                   read.close();
                   read = null;
               }
               if (null != is) {
                   is.close();
                   is = null;
               }
           } catch (IOException e) {
           }
       }
       return res.toString();
   }

 

你可能感兴趣的:(将一个InputStream流转换成字符串)