厚德博学 敬业乐群
@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
格伯纳
分类:
2009-07-03 08:25:22
import java.io.PipedReader; import java.io.PipedWriter; import java.io.Reader; import java.io.Writer; import java.io.BufferedReader; import java.io.InputStreamReader; class ReadThread extends Thread { private PipedReader reader; public ReadThread(PipedReader reader) { this.reader = reader; } public void run() { char[] data = new char[1024]; int len; while (true) { try { len = reader.read(data, 0, data.length); if (len == -1) break; else System.out.println(new String(data, 0, len)); } catch(Exception e) { e.printStackTrace(); } } } } public class tmp { public static void main(String args[]) throws Exception { PipedReader reader = new PipedReader(); PipedWriter writer = new PipedWriter(); ReadThread t = new ReadThread(reader); t.start(); writer.connect(reader); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); char[] data = new char[1024]; int len; while (true) { len = in.read(data, 0, data.length); if (len == -1) break; else writer.write(data, 0, len); } in.close(); writer.flush(); writer.close(); reader.close(); } }
上一篇:java PipedInputStream和PipedOutputStream用法
下一篇:java FileChannel用法
登录 注册