本文主要是介绍Java InputStream OutputStream,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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();
这篇关于Java InputStream OutputStream的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!