批量命名工具类

批量命名工具类:

package com.hoo.util;
 
import java.io.File;
 
/**
 * <b>function:</b> 文件命名工具类
 * @author hoojo
 * @createDate 2012-5-14 下午01:58:14
 * @file FileRenameUtils.java
 * @package com.hoo.util
 * @blog http://blog.csdn.net/IBM_hoojo
 * @email hoojo_@126.com
 * @version 1.0
 */
public abstract class FileRenameUtils {
    
    private final static String FILE_PATH = "D:\\apache-tomcat-6.0.33\\webapps\\jwchat";
    
    /**
     * <b>function:</b> 将指定目录下的文件的type类型的文件,进行重命名,命名后的文件将去掉type
     * <p>example: 如果type = html; index.html.html -> index.html</p>
     * <p>example: 如果type = zh_CN; index.html.zh_CN -> index.html</p>
     * @author hoojo
     * @createDate 2012-5-16 下午02:16:48
     * @param path
     * @param type
     */
    public static void rename(String path, String type) {
        if (path == null || "".equals(path)) {
            path = FILE_PATH;
        }
        File dir = new File(path);
        File[] list = dir.listFiles();
        for (File file : list) {
            String name = file.getName();
            String[] s = name.split("\\.");
            if (s.length == 3 && type.equals(s[2])) {
                System.out.println(s[0] + "--" + s[1] + "--" + s[2]);
                file.renameTo(new File(path + "/" + s[0] + "." + s[1]));
            }
        }
    }
    
    public static void main(String[] args) {
    FileRenameUtils.rename("D:\\apache-tomcat-6.0.33\\webapps\\jwchat", "zh_CN");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值