java多线程使用PipedOutStream和PipedInputStream

  <前>   package 测试;   import  java.io.PipedInputStream;   import  java.io.PipedOutputStream;   public  class  PipeTest  {   public  static  void  main (String [], args), throws  Exception  {   PipedOutputStream  pos =, new  PipedOutputStream ();   PipedInputStream  pis =, new  PipedInputStream ();//链接   pis.connect (pos);//写线程   InThread  it =, new  InThread (pos、π);//读线程   OutThread  ot =, new  OutThread (pos、π);   it.start ();   ot.start ();   thread . sleep (1000);   }   }   class  InThread  extends 螺纹{   PipedOutputStream  pos =,空;   PipedInputStream  pis =, null ;   InThread (PipedOutputStream  pos PipedInputStream  pis ) {   时间=this.pos  pos;   this.pis =,π;   }   public  void  run (), {   try  {//写入数据   时间=byte [], b  new 字符串(“却;能够is  a  test  !“) .getBytes ();   pos.write (b);//关闭链接,此处必须关闭,不然会包异常,,   pos.close ();   },catch  (Exception  e), {//,TODO  Auto-generated  catch 块   e.printStackTrace ();   }   }   }   class  OutThread  extends 螺纹{   PipedInputStream  pis =, null ;   PipedOutputStream  pos =,空;   OutThread (PipedOutputStream  pos PipedInputStream π){   this.pis =,π;   时间=this.pos  pos;   }   public  void  run (), {//读取数据   String  m =,““   时间=byte [], b  new 字节[1024];   try  {   int  len ;   时间=len  pis.read (b);   时间=m  m +, new 字符串(b);   而(len !=1), {   len =, pis.read (b),,   时间=m  m +, new 字符串(b);   }//关闭资源   pis.close ();   System.out.println (m);   },catch  (Exception  e), {//,TODO  Auto-generated  catch 块   e.printStackTrace ();   }   }   }   之前   

  
  

java多线程使用PipedOutStream和PipedInputStream