标签:
import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputStream; public class FileIO{ public static void main(String []args){ Send send=new Send(); Recive recive=new Recive(); try { send.getOut().connect(recive.getIn()); } catch (IOException e) { e.printStackTrace(); } new Thread(send).start(); new Thread(recive).start(); } } class Send implements Runnable{ private PipedOutputStream out=null; public Send(){out =new PipedOutputStream();}//构造方法 public PipedOutputStream getOut(){return this.out;} public void run() { String str="hello,Mr Zhou"; try { out.write(str.getBytes()); } catch (IOException e) { e.printStackTrace(); } try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } class Recive implements Runnable{ private PipedInputStream in=null; public Recive(){in=new PipedInputStream();} public PipedInputStream getIn(){return this.in;} public void run() { byte []by=new byte[1024]; int len = 0; try { len=in.read(by); } catch (IOException e) { e.printStackTrace(); } try { in.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("接受内容为:"+(new String(by,0,len))); } }
标签:
原文地址:http://www.cnblogs.com/gugibv/p/5130259.html