- import java.io.*;
- import java.util.*;
- class SequenceDemo
- {
- public static void main(String[] args)throws IOException
- {
- Vector<FileInputStream> v = new Vector<FileInputStream>();
- v.add(new FileInputStream("c:\\1.txt"));
- v.add(new FileInputStream("c:\\2.txt"));
- v.add(new FileInputStream("c:\\3.txt"));
- Enumeration<FileInputStream> en = v.elements();
- SequenceInputStream sis = new SequenceInputStream(en);
- FileOutputStream fos = new FileOutputStream("c:\\4.txt");
- byte[] buy = new byte[1024];
- int len = 0;
- while((len=sis.read(buy))!=-1)
- {
- fos.write(buy,0,len);
- }
- fos.close();
- sis.close();
- }
- }
- 1.txt
- 1
- 11
- 111
- 2.txt
- 2
- 22
- 222
- 2222
- 3.txt
- 3
- 33
- 333
- 3333
- 输出的4.txt
- 1
- 11
- 1112
- 22
- 222
- 22223
- 33
- 333
- 3333
- 怎么是这样,不应该是
- 1
- 11
- 111
- 2
- 22
- 222
- 2222
- 3
- 33
- 333
- 3333
- 这样的吗?谁帮忙解释一下,怎么回事?
复制代码 |
|