IO流——(18)管道流PipedInputStream&PipedOutputStream

 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();
        }

    }
}

发布了186 篇原创文章 · 获赞 45 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/zhanshixiang/article/details/103916971