读书人

按年月日创设文件夹

发布时间: 2012-12-26 14:39:29 作者: rapoo

按年月日创建文件夹

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);}

?

读书人网 >编程

热点推荐