//文件的切割流和合并流
import java.io.*;
import java.util.*;
class SplitDemo
{
public static void main(String[] args) throws IOException
{
method2();
}
public static void method2()throws IOException//此方法使用ArrayList存储FileInputStream对象,并使用Enumeration匿名内部类
{
ArrayList<FileInputStream>al=new ArrayList<FileInputStream>();
for (int x=1;x<7 ;x++ )
{
al.add(new FileInputStream("F:"+File.separator+"haha"+File.separator+"part"+x+".part"));
}
final Iterator<FileInputStream>it=al.iterator();
Enumeration<FileInputStream>e=new Enumeration<FileInputStream>()
{
public boolean hasMoreElements()
{
return it.hasNext();
}
public FileInputStream nextElement()
{
return it.next();
}
};
SequenceInputStream sis=new SequenceInputStream(e);
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("f:"+File.separator+"haha111.avi"));
byte by[]=new byte[1024];
int len=0;
while ((len=sis.read(by))!=-1)
{
bos.write(by,0,len);
}
sis.close();
bos.close();
}
public static void method1()throws IOException//此方法是用Vector集合存储FileInputStream 并使用Enumeration
{
Vector<FileInputStream>v=new Vector<FileInputStream>();
for (int x=1;x<7 ;x++ )
{
v.add(new FileInputStream("F:"+File.separator+"haha"+File.separator+"part"+x+".part"));
}
Enumeration<FileInputStream>e=v.elements();
SequenceInputStream sis=new SequenceInputStream(e);
FileOutputStream fos=new FileOutputStream("f:"+File.separator+"haha.avi");
byte by[]=new byte[1024];
int len=0;
while ((len=sis.read(by))!=-1)
{
fos.write(by,0,len);
}
sis.close();
fos.close();
}
public static void method()throws IOException//此方法是切割文件
{
FileInputStream fis=new FileInputStream("2012世界末日.avi");
FileOutputStream fos=null;
byte by[]=new byte[1024*1024];
int len=0;
int count=1;
while ((len=fis.read(by))!=-1)
{
fos=new FileOutputStream("f:"+File.separator+"haha"+File.separator+"part"+(count++)+".part");
fos.write(by,0,len);
fos.close();
}
fis.close();
}
}
文件的切割流和合并流
最新推荐文章于 2021-02-16 02:58:00 发布