黑马程序员技术交流社区
标题:
关于IO流——合并流的问题
[打印本页]
作者:
蓝枫
时间:
2014-4-5 17:15
标题:
关于IO流——合并流的问题
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
这样的吗?谁帮忙解释一下,怎么回事?
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2