序列流

2019-06-26  本文已影响0人  kanaSki

SequenceInputStream
用于将多个流整合为一个

    public static void main(String[] args) throws IOException {
        OutputStream write = new FileOutputStream("2.txt");
        Vector<InputStream> vi = new Vector();
        SequenceInputStream sis = null;
        for (int i = 0; i < 6; i++) {
            InputStream is = new FileInputStream(i + ".txt");
            vi.add(is);
        }
        sis = new SequenceInputStream(vi.elements());
        byte[] buffer = new byte[1024];
        int len = -1;
        while ((len = sis.read(buffer)) != -1) {
            write.write(buffer, 0, len);
            write.flush();
        }
        write.close();
        sis.close();
    }
上一篇下一篇

猜你喜欢

热点阅读