首页 > 其他 > 详细

建立多级文件夹

时间:2016-12-02 21:41:34      阅读:363      评论:0      收藏:0      [点我收藏+]

// 创建多级文件夹
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;
}
}

建立多级文件夹

原文:http://www.cnblogs.com/haorun/p/6127026.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!