📄 class1.java
字号:
import java.io.*;
public class Class1
{
/**
* The main entry point for the application.
*
* @param args Array of parameters passed to the application
* via the command line.
*/
public static void main (String[] args)throws IOException
{
PipedInputStream in=new PipedInputStream();
PipedOutputStream out=new PipedOutputStream();
out.connect(in);
System.out.println("管道已经成功建立!");
Thread t1=new sender(out);
Thread t2=new receiver(in);
t1.start();
t2.start();
// TODO: Add initialization code here
}
}
class sender extends Thread
{
private DataOutputStream sendstream;
public sender(PipedOutputStream out){
sendstream=new DataOutputStream(out);
}
public void run() {
String s="你好,接收者!这是管道流通信测试";
try{
sendstream.writeUTF(s);
sendstream.close();
}
catch(IOException e)
{
System.out.println("error:"+e);
System.exit(-1);
}
}
}
class receiver extends Thread
{
private DataInputStream receivestream;
public receiver(PipedInputStream in){
receivestream=new DataInputStream(in);
}
public void run(){
String s;
try{
s=receivestream.readUTF();
System.out.println("下列信息来自发送者:\n"+s);
receivestream.close();
while (System.in.read()!='1'){}
}
catch(IOException e)
{
System.out.println("error:"+e);
System.exit(-1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -