31.管道流
管道流
PipedInputStream:字节管道输入流
PipedOutputStream:字节管道输出流
PipedReader:字符管道输入流
【31.管道流】PipedWrite:字符管道输出流示例代码
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
class AThread extends Thread{private PipedOutputStream out = null;
public AThread (BThread b) throws IOException{
out = new PipedOutputStream(b.getIn());
}public void run() {
try {
for (int i = 33;
i < 65;
i++) {
out.write(i);
}
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}class BThread extends Thread{private PipedInputStream in = new PipedInputStream();
public PipedInputStream getIn(){
return in;
}public void run() {int len = -1;
try {
while((len = in.read()) != -1){
System.out.println((char)len);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}public class PiedDemo {public static void main(String[] args) throws Exception {BThread b = new BThread();
AThread a = new AThread(b);
a.start();
b.start();
}}
推荐阅读
- live|live to inspire 一个普通上班族的流水账0723
- 流转
- Guava|Guava RateLimiter与限流算法
- angular2内置管道
- (小说)月流水几亿的火爆游戏养成记
- 谁还用剩米饭做蛋炒饭啊,现在流行这么吃!
- 推倒心灵的墙,让爱继续流动
- 迅捷流程图制作软件的使用方法!
- --木木--|--木木-- 第二课作业#翼丰会(每日一淘6+1实战裂变被动引流# 6+1模式)
- 那些年,我们一起追过的《流星雨》