InputStream 轉為 ByteArrayOutputStream
public Reader(InputStream input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
try {
while ((len = input.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
} catch (IOException e) {
throw new Exception("Illegal flow.");
} finally {
try {
input.close();
} catch (IOException e) {
logger.error("file stream shutdown failed.");
}
}
this.baos = baos;
}
ByteArrayOutputStream 轉為 InputStream
private InputStream streamTran(ByteArrayOutputStream in) {
return new ByteArrayInputStream(in.toByteArray());
}
————————————————
版權聲明:本文為CSDN博主「Mr-先森你好」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/u011067966/article/details/97757260