java其他流,SequenceInputStream,ByteArrayOutputStream

  1. SequenceInputStream
        FileInputStream fis1 = new FileInputStream("a.txt");
        FileInputStream fis2 = new FileInputStream("b.txt");
        FileOutputStream fos = new FileOutputStream("c.txt");
        SequenceInputStream sis = new SequenceInputStream(fis1,fis2);
        int len;
        while((len = sis.read()) != -1){
            fos.write(len);
        }
        sis.close();
        fos.close();
  1. Vector v
        FileInputStream fis1 = new FileInputStream("a.txt");
        FileInputStream fis2 = new FileInputStream("b.txt");
        FileInputStream fis3 = new FileInputStream("c.txt");

        Vector<FileInputStream> v = new Vector ();
        v.add(fis1);
        v.add(fis2);
        v.add(fis3); 

        Enumeration<FileInputStream> en = v.elements();

        SequenceInputStream sis = new SequenceInputStream(en);
        FileOutputStream fos = new FileOutputStream("d.txt");

        int len;   
        while((len = sis.read()) != -1){  
            fos.write(len);
        }
        sis.close();
        fos.close();
  1. ByteArrayOutputStream()
        FileInputStream fis = new FileInputStream("d.txt");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int len;
        while((len = fis.read()) != -1){
            baos.write(len);
        } 
        byte arr[] = baos.toByteArray();

        System.out.println(new String(arr));
        System.out.println(baos);
        fis.close();

你可能感兴趣的:(序列流,内存输出流)