厚德博学 敬业乐群
@sky
全部博文(252)
2015年(2)
2014年(1)
2013年(1)
2012年(16)
2011年(42)
2010年(67)
2009年(87)
2008年(36)
25742040
shijiulo
niuxlinu
ebayboy
hayand66
大鬼不动
acer1025
醉鬼的故
小雅贝贝
XINGCHEN
wzy_yzw
十的9次
zds05
bjywxc
zlhc1
smile124
cynthia
格伯纳
分类: LINUX
2009-09-02 17:34:34
import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; class ReadThread extends Thread { public PipedInputStream in; public ReadThread(PipedInputStream in) { this.in = in; } public void connect(PipedOutputStream out) throws Exception { in.connect(out); } public void run() { try { byte[] data = new byte[1024]; int len; len = in.read(data, 0, 1024); in.close(); DataOutputStream out = new DataOutputStream(System.out); out.write(data, 0, len); } catch (Exception e) { System.out.println(e.getMessage()); } } } class WriteThread extends Thread { public PipedOutputStream out; public WriteThread(PipedOutputStream out) { this.out = out; } public void connect(PipedInputStream in) throws Exception { out.connect(in); } public void run() { try { DataInputStream in = new DataInputStream(System.in); byte[] data = new byte[1024]; int len = in.read(data, 0, 1024); out.write(data, 0, len); out.flush(); out.close(); } catch (Exception e) { System.out.println(e.getMessage()); } } } public class Test { public static void main(String args[]) throws Exception { PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(); ReadThread reader = new ReadThread(in); WriteThread writer = new WriteThread(out); writer.connect(in); reader.start(); writer.start(); } }
上一篇:hashmap例子
下一篇:java多线程同步(转载)
登录 注册