Java-管道流
管道流:实现两个线程之间的数据交互.
PipedInputStream
PipedOutputStream
PipedReder
PipedWriter
//线程A发送数据给线程B class Athread extends Thread { private static PipedOutputStream out = new PipedOutputStream(); // 新建一个管道输出流对象 public static PipedOutputStream getOut(){ //用来获取A线程创建的对象 return out; } public void run() { for (int i = 97; i < 117; i++) { try { out.write(i); out.close(); } catch (IOException e) { e.printStackTrace(); } } } } //线程B接收线程A发送的数据 class BThread extends Thread{ PipedInputStream in = null; public PipedInputStream(Athread ){ } } // 管道流 实现线程之间的数据交互 public class PipedStreamDemo { public static void main(String[] args) { } }
共有 0 条评论