PipedInputStream:
方法:
示意图:
PipedOutputStream:
扫描二维码关注公众号,回复:
9027631 查看本文章
多线程通过管道流将 管道输入流与管道输出流对接
/**
* @author James
* @create 2020-01-09 22:57
*/
public class PipedStream {
public static void main(String[] args) throws IOException {
PipedInputStream input =new PipedInputStream();
PipedOutputStream output =new PipedOutputStream();
input.connect(output);
new Thread( new input(input)).start();
new Thread(new output(output)).start();
}
}
class output implements Runnable{
private PipedOutputStream out;
public output(PipedOutputStream out) {
this.out = out;
}
@Override
public void run() {
try {
out.write("管道,接上了..".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}