用法:
将输入流中的数据转化为字符集并返回
package com.example.administrator.demo_sourcedownload;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* 工具类,将输入流转化为字符串并返回
*/
public class StreamTools {
public String readStream(InputStream inputStream) throws Exception{
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
byte[] buffer=new byte[1024];
int len=-1;
while((len=inputStream.read(buffer))!=-1){
byteArrayOutputStream.write(buffer,0,len);
}
inputStream.close();
return byteArrayOutputStream.toString();
}
}