- /*
- 切割文件
- 合并文件
- SequenceInputStream
- */
- import java.io.*;
- import java.util.*;
- class Demo8
- {
- public static void main(String[] args)throws Exception
- {
- BufferedInputStream bis=new BufferedInputStream(new FileInputStream("Dj.mp3"));
- BufferedOutputStream bos=null;
- byte []buf=new byte[1024*1024*2];
- int len=0;
- int count=0;
- while((len=bis.read(buf))!=-1){
- bos=new BufferedOutputStream(new FileOutputStream("split/Dj_"+(++count)+".part"));
- bos.write(buf,0,len);
- bos.close();
- }
- ArrayList<InputStream> al=new ArrayList<InputStream>();
- count=0;
- while(count!=3){
- al.add(new FileInputStream("split/Dj_"+(++count)+".part"));
- }
- final Iterator<InputStream> it=al.iterator();
- Enumeration<InputStream> en=new Enumeration<InputStream>(){
- public boolean hasMoreElements(){
- return it.hasNext();
- }
- public InputStream nextElement(){
- return it.next();
- }
- };
-
- SequenceInputStream sis=new SequenceInputStream(en);
- PrintStream ps=new PrintStream("split/Dj.mp3");
- byte []b=new byte[1024];
- len=0;
- while((len=sis.read(b))!=-1){
- ps.write(b,0,len);
- }
- if(bis!=null)
- bis.close();
- if(bos!=null)
- bos.close();
- sis.close();
- ps.close();
- }
- }
复制代码 |