数据流InputStream转字符串

xiaoxiao2021-02-28  94

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()); // String content=new String(out.toByteArray(),"gbk");//使用构造函数,不指定编码,默认是utf-8 return content; }
转载请注明原文地址: https://www.6miu.com/read-83535.html

最新回复(0)