黑马程序员_文件的合并

来源:互联网 发布:全家福相册排版软件 编辑:程序博客网 时间:2024/06/13 13:45

思路运用SequenceInputStream  然后是有enumeration 然后是Victor 最后判断文件存在的话就加到集合Victor中

class practice25

{
public static void main(String[] args) throws Exception
{

int count=1;
Vector<InputStream> v=new Vector<InputStream>();
File f=new File(count+".part");
while(f.exists())
{
v.add(new FileInputStream(f));
count++;
//System.out.println(count);
f=new File(count+".part");
}
SequenceInputStream sis=new SequenceInputStream(v.elements());
PrintStream ps=new PrintStream("25_copy.mp3");
byte[] b=new byte[1024*1024];
int len;
while((len=sis.read(b))!=-1)
{
ps.write(b,0,len);
ps.flush();
}



}
}
原创粉丝点击