数据流InputStream转字符串


    public static String ScreamToString(InputStream in) throws Exception{
     //定义一个内存输出流
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     int len=0;
     byte[] bt=new byte[1024];
     while((len=in.read(bt))!=-1){
        out.write(bt,0,len);
     }
     String content=new String(out.toByteArray());//使用构造函数的原因是
                                            //还可以通过new String(out.toByteArray(),"utf-8")来设置编码
     return content;
    }

原文地址:https://www.cnblogs.com/gwd1154978352/p/6831905.html