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

📄 pipestreamtest.java

📁 流 的目的在于屏蔽IO操作的复杂性
💻 JAVA
字号:
import java.util.*;
import java.io.*;

public class PipeStreamTest
{
	public static void main(String args[]) throws Exception
	{
		/*建立管道*/
		PipedOutputStream pout = new PipedOutputStream();
		PipedInputStream pin = new PipedInputStream(pout);

		/*构造线程*/
		Producer pro = new Producer(pout);
		Consumer con = new Consumer(pin);

		pro.start();
		con.start();
	}
}

class Producer extends Thread
{
	private DataOutputStream out;

	public Producer(OutputStream os)
	{
		out = new DataOutputStream(os);
	}
	
	public void run()
	{
		try
		{
			out.writeDouble(3.1415926);
			out.flush();
		}
		catch(Exception e)
		{   }
	}
	
}

class Consumer extends Thread
{
	private DataInputStream in;
	
	public Consumer(InputStream is)
	{
		in = new DataInputStream(is);
	}
	public void run()
	{
		try
		{
			double num = in.readDouble();
			System.out.println("The double consumed by consumer is: "+num);
		}
		catch(Exception e)
		{   }
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -