【HttpUrlConnection】自定义StreamToString--流转换成字符串(1.1)

    xiaoxiao2022-06-23  16


    public class StringUtils { public static String StreamToString(InputStream in) throws IOException{ //定义一个内存输出流 ByteArrayOutputStream baos=new ByteArrayOutputStream(); //读取流 byte[] buf = new byte[1024]; int len=-1; while((len=in.read(buf))!=-1){ baos.write(buf,0,len); } //将流转换成字符串 String content = new String(baos.toString()); return content; }}
    转载请注明原文地址: https://ju.6miu.com/read-1123357.html

    最新回复(0)