本帖最后由 途中ms前进 于 2015-5-25 21:09 编辑
import java.util.*;
import java.io.*;
class SplitDemo
{
public static void main(String[] args) throws IOException
{
split();
recover();
}
public static void recover()throws IOException
{ArrayList<FileInputStream> al=new ArrayList<FileInputStream>();
for(int x=1;x<=3;x++)
{
al.add(new FileInputStream("d\\splitfiles\\"+x+".part"));
}
Iterator<FileInputStream> it=al.iterator();
Enumeration<FileInputStream> en=new Enumeration<InputStream>(){
public boolean hasMoreElements()
{
return it.hasNext();
}
public FileInputStream nexElement()
{
return it.next();
}
};
SequenceInputStream sis=new SequenceInputStream(en);
FileOutputStream fos=new FileOutputStream("d:\\splitfiles\\0.bmp");
byte[] buf=new byte[1024];
int len=0;
while((len=sis.read(buf))!=-1)
{
fos.write(buf.0.len);
}
fos.close();
sis.close();
}
public static void splitfile()throws IOException
{FileInputStream fis=new FileInputStream("d:\\1.bmp");
byte[] buf=new byte[1024*1024];
FileOutputStream fos=null;
int count=1;
int len=0;
while((len=fis.read(buf))!=-1)
{
fos=new FileOutputStream("d:\\splitfiles\\"+(count++)+".part");
fos.write(buf,0,len);
fos.close();
}
fis.close();
}
}
|
|