一个简单的File练习代码

来源:互联网 发布:中国网络经纪人安居客 编辑:程序博客网 时间:2024/06/05 20:41

  

import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileFilter;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FilenameFilter;import java.io.IOException;public class FileIntegration {/** * @param args */public static void main(String[] args) {new FileIntegration().integration("D:/下载/其他工具/视频", "D:/54321.flv", "flv");}//path1-->合集全目录    path2-->合成后文件绝对位置     type -->需要合成的文件格式public void integration(String path1 , String path2 ,String type){BufferedInputStream bis  = null;BufferedOutputStream bos = null;try {File[] paths = null;byte[] buf = new byte[1024*1024*10];int len = 0;bos = new BufferedOutputStream(new FileOutputStream(path2));for(File f :(new File(path1).listFiles())){System.out.println("判断前:"+type+"<-->"+f );if(f.isFile() && (f.getName().substring(f.getName().lastIndexOf(".")+1).equals(type) )){bis = new BufferedInputStream(new FileInputStream(f));while((len = bis.read(buf))!=-1){bos.write(buf, 0, len); }System.out.println(">>>>>>>>>>>>>>>>"+f);}}} catch (Exception e) {e.printStackTrace();}finally{try {if(bis!=null){bis.close();}} catch (IOException e) {e.printStackTrace();}try {if(bos!=null){bos.flush();bos.close();}} catch (IOException e) {e.printStackTrace();}}}} 



 

0 0