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文件系统磁盘中,否则可能修改不成功。原因待研究。。。
  • 相关阅读:
    POJ-2393
    POJ-1328
    POJ-2376
    CF-811B
    CF-811A
    CF-816B
    P1111 修复公路
    P2777 [AHOI2016初中组]自行车比赛
    P1889 士兵站队
    P1459 三值的排序 Sorting a Three-Valued Sequence
  • 原文地址:https://www.cnblogs.com/crane13/p/3150123.html
Copyright © 2011-2022 走看看