waynelsh

导航

io包--File类的一个小应用--批量重命名

    public static void main(String[] args) {
        String path = "G:/工作/test";

        File file = new File(path);
        System.out.println(file.exists());
        File[] files = file.listFiles();
        if (null != files && files.length > 0) {
            for (File file1 : files) {
                if (file1.isFile()) {
                    String absolutePath = file1.getAbsolutePath();
                    System.out.println(absolutePath);
                    String temp = "测试";
                    if (absolutePath.contains(temp)) {
                        String replace = absolutePath.replace(temp, "test");
                        File file2 = new File(replace);
                        file1.renameTo(file2);
                    }
                }
            }
        }
    }
    

posted on 2018-04-19 23:33  waynelsh  阅读(112)  评论(0编辑  收藏  举报