欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入
* @param in InputStream
* @return byte[]
* @throws IOException
*/
public static byte[] InputStreamTOByte(InputStream in) throws IOException{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[BUFFER_SIZE];
int count = -1;
while((count = in.read(data,0,BUFFER_SIZE)) != -1)
outStream.write(data, 0, count);
data = null;
return outStream.toByteArray();
}
/**
* 将byte数组转换成InputStream
* @param in
* @return
* @throws Exception
*/
public static InputStream byteTOInputStream(byte[] in) throws Exception{
ByteArrayInputStream is = new ByteArrayInputStream(in);
return is;
}
/**
* 将byte数组转换成String
* @param in
* @return
* @throws Exception
*/
public static String byteTOString(byte[] in) throws Exception{
InputStream is = byteTOInputStream(in);
return InputStreamTOString(is);
}
}
[1][2]
你不勇敢,没人替你坚强!