码迷,mamicode.com
首页 > 其他好文 > 详细

SequenceInputStream的用法(用来合并流然后一起操作)

时间:2019-11-09 09:36:19      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:tor   eth   read   err   for   pre   method   ati   input   

package test;
 
 
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.InflaterInputStream;
 
import javax.annotation.processing.FilerException;
import javax.management.RuntimeErrorException;

import privateclass.Filterby_Name;
import privateclass.Filterby_hidden;
import privateclass.Filterby_java;
import privateclass.MyBufferedReader;
 
public class Main {
 
    private static final String space_operator = " ";
    private static final double pi = Math.PI;
    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
    public static void main(String[] args) throws Exception {
 
    	/*
    	 * 我们可以通过vector获取一个Enumeration的枚举对象
    	 
    	Vector<FileInputStream> vector = new Vector<FileInputStream>();
    	vector.add(new FileInputStream("1.txt"));
    	vector.add(new FileInputStream("2.txt"));
    	vector.add(new FileInputStream("3.txt"));
    	vector.add(new FileInputStream("4.txt"));
    	
    	Enumeration<FileInputStream> en = vector.elements();
    	*/
    	
    	/*
    	 *思考我们可不可以用list获取
    	 *
    	 */
    	ArrayList<FileInputStream> list = new ArrayList<FileInputStream>();
    	list.add(new FileInputStream("1.txt"));
    	list.add(new FileInputStream("2.txt"));
    	list.add(new FileInputStream("3.txt"));
    	list.add(new FileInputStream("4.txt"));
    	
    	//这就是用到迭代器原理来获取Enumeration
    	/*
    	Iterator<FileInputStream> it = list.iterator();
    	Enumeration<FileInputStream> en = new Enumeration<FileInputStream>(){

			@Override
			public boolean hasMoreElements() {
				// TODO Auto-generated method stub
				return it.hasNext();
			}

			@Override
			public FileInputStream nextElement() {
				// TODO Auto-generated method stub
				return it.next();
			}
    		
    	};
    	*/
    	
    	//直接用Collections里面封装的方法
    	Enumeration<FileInputStream> en = Collections.enumeration(list);
    	
    	SequenceInputStream sis = new SequenceInputStream(en);
    	
    	FileOutputStream fos = new FileOutputStream("7.txt");
    	int len = 0;
    	byte[] buf = new byte[1024];
    	while((len = sis.read(buf)) != -1)
    	{
    		fos.write(buf,0,len);
    	}
    	
    	fos.close();
    	sis.close();
    	
    	
    }
	
}

  

SequenceInputStream的用法(用来合并流然后一起操作)

标签:tor   eth   read   err   for   pre   method   ati   input   

原文地址:https://www.cnblogs.com/WINDZLY/p/11823945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!