📄 pipedstreamtest.java
字号:
import java.io.*;
class PipedStreamTest
{
public static void main(String[] args) throws IOException
{
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream();
pos.connect(pis);
new Producer(pos).start();
new Consumer(pis).start();
}
}
class Producer extends Thread
{
private PipedOutputStream pos = new PipedOutputStream();
Producer(PipedOutputStream pos)
{
this.pos = pos;
}
public void run()
{
try
{
pos.write("My name is oyqd".getBytes());
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}
class Consumer extends Thread
{
private PipedInputStream pis = new PipedInputStream();
Consumer(PipedInputStream pis)
{
this.pis = pis;
}
public void run()
{
try
{
byte[] data = new byte[100];
int len = pis.read(data);
System.out.println(new String(data, 0, len));
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -