本帖最后由 哈达洋 于 2014-10-18 00:01 编辑
- <div class="blockcode"><blockquote>import java.io.*;
- import java.util.*;
- class VideoSplit
- {
- public static void main(String[] args) throws Exception
- {
- File file = new File("g:\\超凡蜘蛛侠2.BD.720p.中英双字幕.rmvb");
- //split(file);
- merge();
- }
- public static void merge() throws Exception
- {
- ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
- for(int i=0;i<4;i++)
- {
- al.add(new FileInputStream("g:\\part\\"+i+".part"));
- }
- 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);
- BufferedOutputStream bos =
- new BufferedOutputStream(new FileOutputStream("g:\\part\\spilderman.rmvb"));
- byte[] buf = new byte[1024*1024*10];
- int len=0;
- while((len=sis.read(buf))!=-1)
- {
- bos.write(buf,0,len);
- bos.flush();
- }
- bos.close();
- sis.close();
-
- }
- public static void split(File file) throws Exception
- {
- if(!file.exists())
- {
- System.out.println("文件不存在");
- return;
- }
- else
- {
- BufferedInputStream bis =
- new BufferedInputStream(new FileInputStream(file));
- //定义一个10M的缓冲,虽然BufferedInputStream自带了缓冲,
- //但是这里再定义一个缓冲,在写入的时候,会更快。
- byte[] buf1 = new byte[1024*1024*10];
- BufferedOutputStream bos =null;
- int len=0;
- int count=0;
- while((len=bis.read(buf1))!=-1)
- {
-
- if(count%50==0)//按500M分割
- {
- bos = new BufferedOutputStream(new FileOutputStream("g:\\part\\"+(count/50)+".part"));
- }
- count++;
- bos.write(buf1,0,len);
- bos.flush();
- if(count%50==0)
- {
- bos.close();
- }
- }
- bis.close();
- bos.close();
- }
- }
- }
复制代码
|