// 创建多级文件夹
public static String addFilePath(String path) throws Exception {
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
int date = c.get(Calendar.DATE);
int hour = c.get(Calendar.HOUR_OF_DAY);
String resultPath = path + "/" + "" + year + month + "/" + date + "/" + hour + "/";
createDirectory(resultPath);
return resultPath;
}
public static void createDirectory(String path) throws Exception {
if (StringUtils.isNullOrEmpty(path)) {
return;
}
try {
// 获得文件对象
File f = new File(path);
if (!f.exists()) {
// 如果路径不存在,则创建
f.mkdirs();
}
} catch (Exception e) {
throw e;
}
}