OutputStream 轉 InputStream
Case 1 toByteArray
ByteArrayOutputStream out = new ByteArrayOutputStream();
new ByteArrayInputStream(out.toByteArray())
Case2 從Output字節讀取Input
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] bs = new byte[] { 1, 2, 3, 4, 5 };
out.write(bs);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray())
byte[] bs = new byte[1024];
int len = in.read(bs);
for (int i = 0; i < len; i++) {
System.out.println(bs[i]);
}
InputStream 轉OutputStream
PipedInputStream in = new PipedInputStream();
PipedOUtputStream out = new PipedOutputStream(in);
OutputStream outputStream = null
OutputStream接收數據前,需要new出空間來,否則會報null。
OutputStream outputStream = new ByteArrayOutputStream();