A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© gjf821687 中级黑马   /  2016-9-6 19:53  /  278 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class SequenceInputStreamTest {
        public static void main(String[] args) {
                Vector<FileInputStream> v = new Vector<>();
                SequenceInputStream sis = null;
                FileOutputStream fos = null;
                try {
                        v.add(new FileInputStream("e:\\copyfile\\1.txt"));
                        v.add(new FileInputStream("e:\\copyfile\\2.txt"));
                        v.add(new FileInputStream("e:\\copyfile\\3.txt"));
                        Enumeration<FileInputStream> en = v.elements();
                       
                        sis = new SequenceInputStream(en);
                        fos = new FileOutputStream("e:\\copyfile\\4.txt");
                       
                        byte[] buf = new byte[1024];
                        int len = 0;
                        while((len = sis.read(buf)) != -1){
                                fos.write(buf,0,len);
                        }
                       
                } catch (FileNotFoundException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();
                }finally{
                        if(fos == null)
                                try {
                                        fos.close();
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        if(sis == null)
                                try {
                                        sis.close();
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                }
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马