码迷,mamicode.com
首页 > 其他好文 > 详细

建立多级文件夹

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

标签:ret   util   dir   path   pat   null   row   文件   cep   

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

建立多级文件夹

标签:ret   util   dir   path   pat   null   row   文件   cep   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!