zoukankan      html  css  js  c++  java
  • java批量修改文件名

    代码:
    import java.io.File;
    import java.io.IOException;
     
    public class FileRename {
    public static void main(String[] args) throws IOException {
    File file = new File("E:/path");
    if (file == null) {
    return;
    }
     
    if (file.isDirectory()) {
    String newName;
    String[] files = file.list();
    for (int i = 0; i < files.length; i++) {
    File f = new File(file, files[i]);
    String name = f.getCanonicalPath();
    newName = name.replace("W", "").replace("D", "").replace("+", "-");
    boolean b =   f.renameTo(new File(newName));
    System.out.println(newName+"---b:"+b);
    }
    }
    }
     
    }
     
    文件需放在FAT32文件系统磁盘中,否则可能修改不成功。原因待研究。。。
  • 相关阅读:
    Python下载安装
    批量修改样式及全选反选
    小99
    练习题
    练习
    对象、函数
    操作document对象练习
    练习题
    0513-2
    0513-1
  • 原文地址:https://www.cnblogs.com/crane13/p/3150123.html
Copyright © 2011-2022 走看看