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

    }
    }
  • 相关阅读:
    xcode中的udp接收数据
    FMX.MEDIA中的录音功能实现
    DELPHI XE功能
    xcode 中运用lame进行caf文件到mp3文件的转换
    xcode中用AVAudioRecorder录音到指定的caf文件
    enum 在c中的使用(枚举类型)
    c语言中typedef的几种用法
    pta 两个有序链表序列的交集
    Level-order Traversal(c语言函数指针样例)
    求二叉树高度
  • 原文地址:https://www.cnblogs.com/Shock-W/p/6039501.html
Copyright © 2011-2022 走看看