码迷,mamicode.com
首页 > 编程语言 > 详细

java 改文件名的例子

时间:2016-08-16 16:00:43      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

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

 

java 改文件名的例子

标签:

原文地址:http://www.cnblogs.com/zhengchunhao/p/5776556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!