码迷,mamicode.com
首页 > 其他好文 > 详细

管道流 pipedinputstream

时间:2016-01-24 15:30:45      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

public class StreamDemo3 {
public static void main(String[] args) {
try {
//管道流
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream(in);
Send send = new Send(out);
Receiver rec = new Receiver(in);
send.send();
rec.rec();
//关闭省略了
} catch (Exception e) {
e.printStackTrace();
}
}
}
class Send{
OutputStream out;

public Send(OutputStream out) {
super();
this.out = out;
}
public void send(){
try {
byte value =(byte)(Math.random()*100);
System.out.println("send the value is:"+value);
out.write(value);
} catch (Exception e) {
e.printStackTrace();
}
}
}
class Receiver{
InputStream in;

public Receiver(InputStream in) {
super();
this.in = in;
}
public void rec(){
try {
byte value =(byte)in.read();
System.out.println("rec the value is :"+value);
} catch (Exception e) {
e.printStackTrace();
}
}
}

管道流 pipedinputstream

标签:

原文地址:http://www.cnblogs.com/shaoshanhuo/p/5155108.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!