首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

按年月日创设文件夹

2012-12-26 
按年月日创建文件夹import java.io.Fileimport java.util.Calendarimport org.apache.struts2.ServletAc

按年月日创建文件夹

import java.io.File;import java.util.Calendar;import org.apache.struts2.ServletActionContext; private static final Logger logger = Logger.getLogger(PictureAction.class);

?

按年月创建文件夹:?

?

Calendar cad = Calendar.getInstance();String month=String.valueOf(cad.get(Calendar.MONTH) + 1);if(month.length()<2){month=0+month;}//相对存放路径String savePath = "/upload/picture/"+String.valueOf(cad.get(Calendar.YEAR))+ month;try {File dirFile = new File(ServletActionContext.getServletContext().getRealPath(savePath));boolean bFile = dirFile.exists();if (bFile == true) {//The folder exists.} else {//The folder do not exist,now trying to create a one.bFile = dirFile.mkdir();if (bFile == true) {//Create successfully!} else {//Disable to make the folder,please check the disk is full or not.logger.error("[java]PictureAction create folder is error,because Disable to make the folder,please check the disk is full or not.");}}} catch (Exception err) {logger.error("[java]PictureAction create folder is error,because the disk is full or not.", err);}

?

热点排行