📄 pipestream1.java
字号:
import java.io.*;
class PipeStream1
{
public static void main(String args[])
{
try
{
//创建管道输入流
PipedInputStream in = new PipedInputStream();
//创建管道输出流
PipedOutputStream out = new PipedOutputStream();
//输入与输出流相连
out.connect(in);
//创建并启动管道输入线程
PipeSender t1=new PipeSender(out);
t1.start();
//创建并启动管道输出线程
PipeReciver t2=new PipeReciver(in);
t2.start();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
//管道输入类
class PipeSender extends Thread
{
private PipedOutputStream out;
//构造函数
PipeSender(PipedOutputStream out)
{ this.out = out; }
public void run()
{
try
{
out.write("hello world".getBytes());
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
//管道接收类
class PipeReciver extends Thread
{
private PipedInputStream in;
//构造方法
PipeReciver (PipedInputStream in)
{ this.in = in; }
public void run()
{
try
{
byte buf[]=new byte[1024];
int len=in.read(buf);
in.close();
System.out.println(new String(buf,0,len));
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -