JavaLearning:JAVA IO Piped流
2023-09-14 09:10:08 时间
package org.fun.io; import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputStream; class Send implements Runnable{ private PipedOutputStream output=null; public Send(){ this.output=new PipedOutputStream(); } public PipedOutputStream getPipedOutputStream(){ return this.output; } public void run() { String str="hello world!"; try{ this.output.write(str.getBytes()); }catch(IOException e){ e.printStackTrace(); } try{ this.output.close(); }catch(IOException e){ e.printStackTrace(); } } } class Receive implements Runnable{ private PipedInputStream input=null; public Receive(){ this.input=new PipedInputStream(); } public PipedInputStream getPipedInputStream(){ return this.input; } public void run() { byte[] b=new byte[1024]; int len=0; try { len=this.input.read(b); } catch (IOException e) { e.printStackTrace(); } try { input.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println(new String(b,0,len)); } } public class PipedDemo { public static void main(String[] args) throws IOException { Send send=new Send(); Receive rec=new Receive(); send.getPipedOutputStream().connect(rec.getPipedInputStream()); new Thread(send).start(); new Thread(rec).start(); } }
相关文章
- Java(Android)线程池
- java.lang.IndexOutOfBoundsException at java.io.FileOutputStream.writeBytes(Native Method)
- JAVA-JSP内置对象之session对象获得session的其他信息
- Java IO--BufferedReader
- Java IO--打印流PrintStream
- Java IO--RandomAccessFile类
- java:jsp: 一个简单的自定义标签 tld
- Java IO 总结图
- Java实现 LeetCode 213 打家劫舍 II(二)
- Java实现LeetCode_0007_ReverseInteger
- java实现第四届蓝桥杯幸运数
- Java中IO软件包的详细介绍
- java IO之 序列流 集合对象Properties 打印流 流对象
- Java IO 之 InputStream源码
- Java核心知识点学习----使用Condition控制线程通信
- java基础之IO
- Java IO模型详解
- Java和ABAP里的外部类和内部类
- Atitit Java OpenCV 捕获视频
- Java 8 Lambda 表达式
- 计算器Java版(小玩具)
- java 关于 重写、覆写、覆盖、重载 的总结【不想再傻傻分不清了】
- Java——设计模式(装饰模式_IO)
- JAVA学习课第五 — IO流程(九)文件分割器合成器
- 【java基础】Socket网络编程
- 【SpringBoot8】HandlerInterceptor拦截器的使用 ——自@RequestBody获取请求参数解决java.io.IOException: Stream closed
- java入门 常见问题0005:不注意代码的层级结构,main方法放到非静态内部类中,执行出错