⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pipedstreamtest.java

📁 孙鑫JAVA从入门到精通配套练习程序。所有程序都实际运行过
💻 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 + -