学习了JAVA基础的sequenceInputStream后自己写个个分割视频和合并视频的程序,可是每次分割后大小就变化了。合并后也不是原视频了。求解?
- public static void merge() throws IOException{
- ArrayList<FileInputStream> list=new ArrayList<FileInputStream>();
- for(int i=0;i<12;i++){
- list.add(new FileInputStream("E:\\myeclipseJava\\day20\\"+(i+1)+".part"));
- }
- final Iterator<FileInputStream> it=list.iterator();
- Enumeration<FileInputStream> en=new Enumeration<FileInputStream>() {
- @Override
- public boolean hasMoreElements() {
- // TODO Auto-generated method stub
- return it.hasNext();
- }
- @Override
- public FileInputStream nextElement() {
- // TODO Auto-generated method stub
- return it.next();
- }
- };
- SequenceInputStream sis=new SequenceInputStream(en);
- BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("E:\\myeclipseJava\\day20\\temp.rmvb"));
- byte[] byts=new byte[1024*1024];
- int len=0;
- while((len=sis.read(byts))!=-1){
- bos.write(byts, 0, len);
- }
- sis.close();
- bos.close();
- }
- public static void part(){
- BufferedInputStream fis=null;
- BufferedOutputStream fos=null;
- try{
- fis=new BufferedInputStream(new FileInputStream("E:\\myeclipseJava\\day20\\0.rmvb"));
- byte[] byts=new byte[1024*1024*2];
- int len=0;
- int count=1;
- int sum=0;
- while((len=fis.read(byts))!=-1){
- if(sum==0){
- fos=new BufferedOutputStream(new FileOutputStream("E:\\myeclipseJava\\day20\\"+(count++)+".part"));
- fos.write(byts, 0, len);
- sum++;
- }else if(sum<50&&sum>0){
- fos.write(byts,0,len);
- sum++;
- }else{
- fos.close();
- sum=0;
- }
- }
- }catch(IOException e){
- throw new RuntimeException("wrong");
- }finally{
- if(fis!=null){
- try{
- fis.close();
- }catch(IOException e){
- e.getStackTrace();
- }
- }
- if(fos!=null){
- try{
- fis.close();
- }catch(IOException e){
- e.getStackTrace();
- }
- }
- }
- }
复制代码
|