JAVA clone 复制 inputstream
2016-05-20 15:47
447 查看
ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Fake code simulating the copy // You can generally do better with nio if you need... // And please, unlike me, do something about the Exceptions :D byte[] buffer = new byte[1024]; int len; while ((len = input.read(buffer)) > -1 ) { baos.write(buffer, 0, len); } baos.flush(); // Open new InputStreams using the recorded bytes // Can be repeated as many times as you wish InputStream is1 = new ByteArrayInputStream(baos.toByteArray()); InputStream is2 = new ByteArrayInputStream(baos.toByteArray());
对于大多数 InputStream 输入流用过之后,就会关闭。怎样重复使用呢?
阅读更多相关文章推荐
- 关于Java对象复制(Clone、深度Clone以及序列化与反序列化的使用)
- Java中clone方法以及深复制和浅复制
- java实现深复制:clone()及序列化
- JAVA中IO流文件文本的操作(字节流InputStream和OutputStream)字节流File读写操作以及图片的复制
- Java Clone(类的复制)实例代码
- java中的clone:深复制和浅复制
- 详解Java clone深复制和浅复制
- java InputStream 复制
- 浅复制和深度复制 clone() Thinking in java 读书笔记(一)
- Java中的数组复制(clone与arraycopy)代码详解
- (2.1.9)java的clone和浅复制克隆、深复制克隆
- java数组复制===clone()
- java clone和深度复制和浅复制的个人总结
- Java的clone():深复制与浅复制
- java clone 中的浅复制和深复制
- java中equals和==之间的区别?clone方法的作用,及其为什么要使用clone方法?如何使用clone复制对象?以及深克隆浅克隆
- Java中的clone()----深复制,浅复制
- Java中Clone方法的浅复制和深复制
- java clone 对象的深复制(深克隆)和浅复制(浅克隆)介绍
- Rhyme/Java 设计模式之原型模式prototype通过clone方法和反序列化实现深复制