因此本系统的目标就是让顾客方便快捷和满意的购物。为了达到这一目标

源代码在线查看: 有两个线程sender和receiver,sender线程向输出管道out发送数据“hello receiver!”.txt

软件大小: 9708 K
上传用户: jxsflq
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.io.*;
				class Sender extends Thread //发送线程
				{
					private PipedOutputStream out = new PipedOutputStream();
					public PipedOutputStream getOutputStream(){
						return out;
					}
					public void run() {
					  try{
						 String str = new String("Hello,receiver!");
				         for(int i=0;i				            out.write(str.charAt(i));  //依次写入字符串str
				         out.write('.'); //写入结束标记
				         out.close();   
					  }catch(Exception e){
				System.out.println(e.getMessage());
				}
				}
				}
				class Receiver extends Thread
				{
					private PipedInputStream in = new PipedInputStream();
					public PipedInputStream getInputStream(){
				        return in;
					}
					public void run(){
				      int b;
						try{
				while((b=in.read())!='.')  //判断是否为结束标记
				                System.out.print((char)b); //输出接收字符
				         }catch(Exception e){
							 System.out.println(e.getMessage());
				         }
				}
				}
				public class PipedStreamDemo
				{
					  public static void main(String[] args) throws Exception{
				Sender s = new Sender();
				Receiver r = new Receiver();
				PipedOutputStream out = s.getOutputStream();
				PipedInputStream in = r.getInputStream();
				in.connect(out);  //建立连接
					      s.start();
						  r.start();
					  }
				}
							

相关资源