java---序列六(合并流)SequenceInputStream ——对多个流进行合并

package ThreadIO2_1.IO.Sequence;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;

public class SequenceInputStreamDemo {

	public static void main(String[] args) throws IOException {
		FileInputStream fis1 = new FileInputStream("files\\seq1.txt");
		FileInputStream fis2 = new FileInputStream("files\\seq2.txt");
		FileInputStream fis3 = new FileInputStream("files\\seq3.txt");
		ArrayList<FileInputStream> c = new ArrayList<FileInputStream>();
		c.add(fis1);
		c.add(fis2);
		c.add(fis3);
		Enumeration<FileInputStream> e = Collections.enumeration(c);
		SequenceInputStream sis = new SequenceInputStream(e);
		
		//创建输出流---要把前三个文件的内容读出来并且合并到seq4.txt;
		FileOutputStream fos=new FileOutputStream("files\\seq4.txt");
		int len=0;
		byte buf[] = new byte[10];
		while((len=sis.read(buf))!=-1){
			fos.write(buf, 0, len);
		}
		fos.close();
		sis.close();

	}

}

<span style="font-size:18px;color:#ff0000;">总结:将多个流进行逻辑串联(合并变成一个流,操作起来很方便,因为多个源变成了一个源) </span>




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值