import java.text.SimpleDateFormat; import java.util.Calendar; import net.fckeditor.connector.ConnectorServlet; import org.apache.commons.lang.StringUtils; public class FileUtl { /** * 文件重命名(带后缀) * @param fileName * @return */ public static String replaceFileName(String fileName) { StringBuilder builder = new StringBuilder(); if (StringUtils.isNotEmpty(fileName)) { int index = fileName.lastIndexOf("."); if (index > 0) { SimpleDateFormat format = new SimpleDateFormat( "yyyyMMddHHmmssSSS"); String suffix = fileName.substring(index);// 文件后缀名 Calendar cal = Calendar.getInstance(); builder.append(format.format(cal.getTime())); builder.append(suffix); } } return builder.toString(); } /** * 文件重命名(不带后缀) * @param fileName * @return */ public static String replaceName(String fileName) { StringBuilder builder = new StringBuilder(); if (StringUtils.isNotEmpty(fileName)) { SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS"); Calendar cal = Calendar.getInstance(); builder.append(format.format(cal.getTime())); } return builder.toString(); } }
最近下载更多