zoukankan      html  css  js  c++  java
  • java文件复制(可过滤)

    1.java将制定的后缀文件导出到另一个文件中,递归遍历某个文件夹下的所有文件

    直接贴上代码

    import java.io.*;

    public class FileExport {/**
    * Created by Administrator on 2016/11/7 0007.
    */
    public static void main(String[] args){
    String path = "F:\百度云盘\Scala";
    traverseFolder2(path);

    }
    public static void traverseFolder2(String path){
    File file = new File(path);
    if (file.exists()) {
    File[] files = file.listFiles();
    if (files.length == 0) {
    System.out.println("文件夹是空的!");
    return;
    } else {
    for (File file2 : files) {
    if (file2.isDirectory()) {
    //判断后缀是否是mp4,是的话导出即可
    if(file2.getAbsolutePath().contains("mp4"))
    {
    String tempStr = file2.getAbsolutePath().split("\\")[file2.getAbsolutePath().split("\\").length - 1];
    ExceptionDoing(file2.getAbsolutePath(),"C:\Users\Administrator\Desktop\scala视频\" + tempStr);
    }
    traverseFolder2(file2.getAbsolutePath());
    } else {
    if(file2.getAbsolutePath().contains("mp4"))
    {
    String tempStr = file2.getAbsolutePath().split("\\")[file2.getAbsolutePath().split("\\").length - 1];
    ExceptionDoing(file2.getAbsolutePath(),"C:\Users\Administrator\Desktop\scala视频\" + tempStr);
    }
    }
    }
    }
    } else {
    System.out.println("文件不存在!");
    }
    }
    public static void ExceptionDoing(String sourceFile,String targetFile){
    try {
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(sourceFile));
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targetFile));
    byte[] b = new byte[1024];
    int len = 0;
    while((len = bis.read(b)) != - 1){
    bos.write(b,0,len);
    bos.flush();
    }
    bos.close();
    bis.close();
    }catch(Exception e){
    e.printStackTrace();
    }

    }
    }
  • 相关阅读:
    App如何选择移动广告平台,开发者2
    mouseover与mouseenter与mousemove差额mouseout与mouseleave差额
    JFinal 的源代码超具体的分析DB+ActiveRecord
    Vim经常使用技巧总结1
    2015第4周四网摘
    Java任务调度
    2015第4周二网摘
    2015第4周一
    2015第三周日
    转SpringSided代码规范遵循
  • 原文地址:https://www.cnblogs.com/Shock-W/p/6039501.html
Copyright © 2011-2022 走看看