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();
    }

    }
    }
  • 相关阅读:
    OLT配置学习
    notepad配合正则表达式处理文本
    利用expect和sshpass完美非交互性执行远端命令
    yum 数据库报错与重构
    杀死dialog
    OLT配置说明
    freeradius下发限速信息字段
    debug调试日志和数据查询
    通过windows的超级终端连接华为交换机
    强制清除交换机端口所有配置
  • 原文地址:https://www.cnblogs.com/Shock-W/p/6039501.html
Copyright © 2011-2022 走看看