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

📄 iodemo8.java

📁 JAVA的一些基础教程
💻 JAVA
字号:
import java.io.*;

public class IODemo8 
	{
	static PipedInputStream 管道输入 = new PipedInputStream();
	static PipedOutputStream 管道输出 = new PipedOutputStream();

	public static void main(String[] args)
	 {
		try 
		{
			管道输入.connect(管道输出);
		}catch(IOException e) 
		{
			System.err.println("连接失败");
			System.exit(1);
		}

		byte[] 读取数据 = new byte[1000];
		int 读取字节数 = 0;
		int i = 0;
		启动写线程();
		try 
			{
			读取字节数 = 管道输入.read( 读取数据);
			while(读取字节数 != -1) {
			i++;
			if(i == 10) System.exit(0);
			System.out.println("已经读取" + 读取字节数 + "字节,还有" + 管道输入.available() + " 个字节");
			读取字节数 = 管道输入.read(读取数据);
			}
		}catch(IOException e) 
		{
			System.err.println("读取输入错误.");
		}
   	 }

	public static void 启动写线程() 
		{
		Runnable r = new Runnable()
			{
			public void run() 
				{
				byte[] 输出数据 = new byte[2000];
				while(true) {
			                  	try 
						{
			                       	 // 在该线程阻塞之前,有最多1024字节的数据被写入
					         管道输出.write(输出数据);
					}catch(IOException e) 
					{
						System.err.println("写操作错误");
					}
					System.out.println("     已经发送2000字节...");
				}
			}		
		};
		new Thread(r).start();	
    } 
} 

⌨️ 快捷键说明

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