zoukankan      html  css  js  c++  java
  • SequenceInputStream

    //合并多个流
        public static void merge3() throws IOException{
            File file1=new File("E:\a.txt");
            File file2=new File("E:\b.txt");
            File file3=new File("E:\c.txt");
            FileOutputStream fileOutputStream=new FileOutputStream("E:\d.txt");
            FileInputStream file1InputStream=new FileInputStream(file1);
            FileInputStream file2InputStream=new FileInputStream(file2);
            FileInputStream file3InputStream=new FileInputStream(file3);
            Vector<FileInputStream> vector=new Vector<FileInputStream>();
            vector.add(file1InputStream);
            vector.add(file2InputStream);
            vector.add(file3InputStream);
            Enumeration<FileInputStream> e=vector.elements();
            SequenceInputStream sequenceInputStream=new SequenceInputStream(e);
            byte[] buf= new byte[1024];
            int length=0;
            while((length=sequenceInputStream.read(buf))!=-1){
                fileOutputStream.write(buf,0,length);
            }
            sequenceInputStream.close();
            fileOutputStream.close();
            
        }
        
        //借助SequenceInputStream合并
        public static void merge2() throws IOException{
            File file1=new File("E:\a.txt");
            File file2=new File("E:\b.txt");
            File outFile=new File("E:\c.txt");
            FileInputStream file1InputStream=new FileInputStream(file1);
            FileInputStream file2InputStream=new FileInputStream(file2);
            FileOutputStream fileOutputStream=new FileOutputStream(outFile);
            SequenceInputStream sequenceInputStream=new SequenceInputStream(file1InputStream, file2InputStream);
            byte[] buf= new byte[1024];
            int length=0;
            while((length=sequenceInputStream.read(buf))!=-1){
                fileOutputStream.write(buf,0,length);
            }
            sequenceInputStream.close();
            fileOutputStream.close();
        
        }
        
        
        //借助数组进行合并
        public static void merge1() throws IOException{
            File file1=new File("E:\a.txt");
            File file2=new File("E:\b.txt");
            File outFile=new File("E:\c.txt");
            FileInputStream file1InputStream=new FileInputStream(file1);
            FileInputStream file2InputStream=new FileInputStream(file2);
            FileOutputStream fileOutputStream=new FileOutputStream(outFile);
            
            ArrayList<FileInputStream> list=new ArrayList<FileInputStream>();
            list.add(file1InputStream);
            list.add(file2InputStream);
            byte[] buf=new byte[1024];
            int length=0;
            for(int i=0;i<list.size();i++){
                FileInputStream fileInputStream=list.get(i);
                while((length=fileInputStream.read(buf))!=-1){
                    fileOutputStream.write(buf,0,length);
                }
                fileInputStream.close();
            }
            fileOutputStream.close();
        }
  • 相关阅读:
    单选框radio 选择问题
    用户名、密码等15个常用的js正则表达式
    mysql创建远程用户并授权
    JS,Jquery获取屏幕的宽度和高度
    ThinkPHP模版时间显示
    composer启用国内镜像网站的配置更改办法
    tp6 使用全局中间件配置验证器
    tp3.2查询当前时间大于已有时间三分钟
    jquery判断手机端或者pc端
    html页面引入公共的页首和导航栏
  • 原文地址:https://www.cnblogs.com/lyjs/p/5005074.html
Copyright © 2011-2022 走看看