zoukankan      html  css  js  c++  java
  • java 改文件名的例子

    public static void main(String[] args)
        {
            File file = new File("E:\\eclipse\\workspace\\helloworlddocker\\log");
         // 判断文件目录是否存在,且是文件目录,非文件
            if (file.exists() && file.isDirectory())
            {
                File[] childFiles = file.listFiles();
                String path = file.getAbsolutePath();
                System.out.println("path: " + path);
                for (File childFile : childFiles)
                {
                    if (childFile.isFile())
                    {
                        String oldName = childFile.getName();
                        if (oldName.substring(0, 4).equals("log."))
                        {
                            String newname;
                            String DateStr = oldName.substring(4);
    
                            newname = "1.1.1.1-histclientsdataetl-" + DateStr.replaceAll("-", "") + ".log";
                            childFile.renameTo(new File(path + "\" + newname));
                        }
                    }
                }
            }
            return;
        }
  • 相关阅读:
    GIT
    curl
    排序算法
    《软件设计师》考点分布
    lua第三方库
    WordPress
    go http
    Unity UI相关总结
    note
    LUA重难点解析
  • 原文地址:https://www.cnblogs.com/zhengchunhao/p/5776556.html
Copyright © 2011-2022 走看看