package com.web.common.util;
import java.io.File;
import java.util.Calendar;
import javax.servlet.http.HttpServletRequest;
public class FilePath {
private static String pathYear;
private static String pathMonth;
private static String pathDay;
private static String pathHour;
private static String pathMinute;
private static String filepath;
public static String getFilePath(String rootPath){
//获取日期
Calendar now = Calendar.getInstance();
filepath = now.get(Calendar.YEAR) + "/" + (now.get(Calendar.MONTH) + 1) + "/" + now.get(Calendar.DAY_OF_MONTH) + "/" + now.get(Calendar.HOUR_OF_DAY) + "/" + now.get(Calendar.MINUTE) + "/";
//年
pathYear = rootPath+ "/"+now.get(Calendar.YEAR);
File fileYear = new File(pathYear);
if (!fileYear.exists()) {
fileYear.mkdirs();
}
//月
pathMonth = pathYear + "/" + (now.get(Calendar.MONTH) + 1);
File fileMonth = new File(pathMonth);
if (!fileMonth.exists()) {
fileMonth.mkdirs();
}
//日
pathDay = pathMonth + "/" + now.get(Calendar.DAY_OF_MONTH);
File fileDay = new File(pathDay);
if (!fileDay.exists()) {
fileDay.mkdirs();
}
//时
pathHour = pathDay + "/" + now.get(Calendar.HOUR_OF_DAY);
File fileHour = new File(pathHour);
if (!fileHour.exists()) {
fileHour.mkdirs();
}
//分
pathMinute = pathHour + "/" + now.get(Calendar.MINUTE);
File fileMinute = new File(pathMinute);
if (!fileMinute.exists()) {
fileMinute.mkdirs();
}
return filepath;
}
}
根据当前日期创建多层文件夹
最新推荐文章于 2023-04-09 00:37:49 发布