程序如下:
public static void merge()
{
ArrayList<FileInputStream> al=new ArrayList<FileInputStream>();
for(int x=1;x<=3;x++)
{
al.add(new FileInputStream("c:\\splits\\"+x+".part"));
}
/*
final Iterator <FileInputStream> it=al.iterator();
Enumeration<FileInputStream> en=new Enumeration<FileInputStream> ()
{
public boolean hasMoreElements()
{
return it.hasNext();
}
public FileInputStream nextElement()
{
return it.next();
}
}
SequenceInputStream sis=new SequenceInputStream (en);
*/
FileOutputStream fos =new FileOutputStream("c:\\splits\\1.bmp");
byte[] buf=new byte[1024];
int len=0;
while((len=sis.read(buf))!=-1)
{
fos.write(buf,0,len);
}
fos.close();
sis.close();
}
请问注释的部分啥思路?本来写Vector集合可以直接使用Enumeration,但考虑到低效就不用vector集合,但这样做高效体现在哪呢? |