📄 pipe.java
字号:
import java.io.*;
class pipe
{
public static void main(String args[])
{
PipedOutputStream out=null;
PipedInputStream in=null;
try
{
out=new PipedOutputStream();
in=new PipedInputStream();
in.connect(out);
}
catch(IOException e){}
thread one =new thread(out,in);
thread2 two=new thread2(in,out);
}
}
class thread extends Thread{
PipedOutputStream out;
PipedInputStream in;
byte b[]={1,2,3};
thread(PipedOutputStream a,PipedInputStream b)
{
try{
out=a;
in=b;
out.connect(in);
}
catch(IOException ioe){}
}
public void run()
{
try{
out.write(b,0,3);
}
catch(IOException dd){}
}
}
class thread2 extends Thread
{
PipedOutputStream out;
PipedInputStream in;
byte a[]=new byte[3];
thread2(PipedInputStream a,PipedOutputStream b)
{
try{
in=a;
out=b;
in.connect(out);
}
catch(IOException ii){}
}
public void run()
{
try{
in.read(a,0,3);
for(int i=0;i<=2;i++)
{
System.out.println(""+a[i]);
}
int c=a[0]+a[1]+a[2];
System.out.println(""+c);
}
catch(IOException e){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -