java能把输出流转换成输入流吗?如果能怎么转,谢谢!

outputstream转成inputstream可行吗?

第1个回答  2015-03-27
你这表达的,输出流有很多种类都是输出流,建议你直接说把什么类转换成什么类,更清晰明了。

ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] bs = new byte[] { 1, 2, 3, 4, 5 };
out.write(bs);

ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
byte[] bs1= new byte[1024];
int len = in.read(bs1);
for (int i = 0; i < len; i++) {
System.out.println(bs[i]);
}
相似回答