IO 流之管道流
2016-04-27 16:57
281 查看
PipedInputStream / PipedOutputStream 实例 :
import java.io.*; class Read implements Runnable { private PipedInputStream in; Read(PipedInputStream in) { this.in = in; } public void run() { try { byte[] buf = new byte[1024]; int len = in.read(buf); String s = new String(buf,0,len); System.out.println(s); in.close(); } catch(IOException e) { throw new RuntimeException("管道读取流失败!"); } } } class Write implements Runnable { private PipedOutputStream out; Write(PipedOutputStream out) { this.out = out; } public void run() { try { out.write("piped a a a a a ".getBytes()); out.close(); } catch(IOException e) { throw new RuntimeException("管道输出流失败!"); } } } class PipedStreamDemo { public static void main(String[] args) throws IOException { PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(); in.connect(out); Read r = new Read(in); Write w = new Write(out); new Thread(r).start(); new Thread(w).start(); } }
相关文章推荐
- 【基础】SublimeText编写MarkDown文档
- Android学习笔记——XML解析
- 个人工作总结9
- 微信网页动画---swiper.animate.css
- IO多路复用之select、poll、epoll详解
- 修改输入框placeholder文字默认颜色-webkit-input-placeholder方法
- ASP.NET MVC数组模型绑定详解
- iOS 四周半透明中间圆形全透明View制作
- Android 设计模式之适配器模式
- json数据的二级联动
- hdu4283——You Are the One(区间dp)
- CC2541之indicate指示
- android volley 框架图片请求后有时会导致第一次初始化过慢的原因
- 前端学习之《JavaScript DOM 编程艺术》读书笔记(5)
- Python 正则表达式:只要整数和小数
- clear read-only status问题的解决
- [置顶] [汇编学习笔记][第十六章直接定址表]
- Ansible Playbook - Understanding YAML
- SQL Server数据库启动过程,以及启动不起来的各种问题的分析及解决技巧
- [汇编学习笔记][第十六章直接定址表]