黑马程序员技术交流社区

标题: SequenceInputStream加ArrayList的使用 [打印本页]

作者: gjf821687    时间: 2016-9-6 21:15
标题: SequenceInputStream加ArrayList的使用
        public static void mothed_2() {
                ArrayList<FileInputStream> list = new ArrayList<>();
                SequenceInputStream sis = null;
                FileOutputStream fos = null;
               
                try {
                        list.add(new FileInputStream("e:\\copyfile\\1.txt"));
                        list.add(new FileInputStream("e:\\copyfile\\2.txt"));
                        list.add(new FileInputStream("e:\\copyfile\\3.txt"));
                       
                        Enumeration<FileInputStream> em = Collections.enumeration(list);
                        sis = new SequenceInputStream(em);
                        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();
                                }
                }
        }
作者: gcno93    时间: 2016-9-6 22:00
一起努力吧,加油!!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2