张孝祥老师的视频都是在一个一个文件夹中,每次都要打开很烦有木有,写个简单小程序剪切出来吧!
- public class CutAVIFile {
- public static void main(String[] args) throws Exception {
- cutAVI("G:\\下载\\12 传智播客[www.itcast.cn]程序员网校[www.it315.org]_张孝祥-7K月薪面试题破解之一_交通灯管理系统视频教程_源代码与PPT",
- "G:\\下载\\12 传智播客[www.itcast.cn]程序员网校[www.it315.org]_张孝祥-7K月薪面试题破解之一_交通灯管理系统视频教程_源代码与PPT");
- }
- /*
- * targetPath:保存着视频的文件夹
- * copy2path:要复制到的文件夹位置
- */
- public static void cutAVI(String targetPath,String copy2path) throws Exception{
- File file = new File(targetPath);
- if(file.isFile()){
- throw new RuntimeException("必须是目录文件");
- }
- System.out.println("path = "+targetPath);
- String[] listFile = file.list();
- File tempFile;
- for(int i=0;i<listFile.length;i++){
- System.out.println("fileName="+listFile[i]);
- if(targetPath.endsWith(File.separator)){
- tempFile = new File(targetPath+listFile[i]);
- }else{
- tempFile = new File(targetPath+File.separator+listFile[i]);
- }
- if(tempFile.isFile()){
- if(tempFile.getAbsolutePath().endsWith(".avi")){
- BufferedInputStream bis = new BufferedInputStream(new FileInputStream(tempFile));
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(copy2path+File.separator+listFile[i]));
- byte[] b = new byte[1024];
- int len = 0;
- while((len = bis.read(b)) != -1){
- bos.write(b, 0, len);
- }
- bos.close();
- bis.close();
- //删除掉该文件
- tempFile.delete();
- }
- }else{
- cutAVI(targetPath+File.separator+listFile[i],copy2path);
- }
- }
- }
- }
复制代码
|
|