pipedstream.java
来自「java2参考大全上的例子的源码和自己的理解.」· Java 代码 · 共 34 行
JAVA
34 行
package pipedstream;
/*
A piped output stream can be connected to a piped input stream to create a communications pipe.
The piped output stream is the sending end of the pipe.
Typically, data is written to a PipedOutputStream object by one thread and data is read from the
connected PipedInputStream by some other thread.
Attempting to use both objects from a single thread is not recommended as it may deadlock the thread.
管道流一定是输入输出并用
例:将数据从输出管道进,从输入管道出
*/
import java.io.*;
class PipedStream {
public static void main(String args[]) throws IOException {
byte aByteData1 = 123, aByteData2 = 111;
PipedInputStream pis =
new PipedInputStream();
PipedOutputStream pos =
new PipedOutputStream(pis);
System.out.println("PipedInputStream");
try {
pos.write(aByteData1);
pos.write(aByteData2);
System.out.println((byte) pis.read());
System.out.println((byte) pis.read());
}
finally {
pis.close();
pos.close();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?