Java核心类库-IO-合并流

合并流/顺序流(sequenceInputStream):

就是把多个输入流,合并成一个流对象。

 1 public class SequenceInputStreamDemo {
 2     public static void main(String[] args) throws Exception {
 3         //创建顺序流对象
 4         SequenceInputStream in = new SequenceInputStream(new FileInputStream("stream.txt"),
 5                 new FileInputStream("stream2.txt"));
 6 
 7         byte[] buffer = new byte[1024];
 8         int len = -1;
 9         while ((len = in.read(buffer)) != -1){
10             System.out.println(new String(buffer,0,len));
11         }
12         in.close();
13     }
14 }

 

posted @ 2017-05-23 20:47  wenxudong  阅读(185)  评论(0编辑  收藏  举报