管道流

管道读取流和管道写入流可以像管道一样对接上,管道读取流就可以读取管道写入流写入的数据。

注意:需要加入多线程技术,因为单线程,先执行read,会发生死锁,因为read方法是阻塞式的,没有数据的read方法会让线程等待。

public static void main(String[] args) throws IOException{

    PipedInputStream pipin = new PipedInputStream();

    PipedOutputStream pipout = new PipedOutputStream();

    pipin.connect(pipout);

    new Thread(new Input(pipin)).start();

    new Thread(new Output(pipout)).start();

}

原文地址:https://www.cnblogs.com/wqing7/p/5896107.html