首页 > 其他 > 详细

管道流 pipedinputstream

时间:2016-01-24 15:28:43      阅读:212      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!