PathUtil

//根據當前時間在給定目錄下創建文件夾
public static String createFolder(String rootPath){
Calendar date = Calendar.getInstance();

SimpleDateFormat formatYear=new SimpleDateFormat("yyyy");
SimpleDateFormat formatMonth=new SimpleDateFormat("MM");
SimpleDateFormat formatDay=new SimpleDateFormat("dd");
String folderNameYear = formatYear.format(date.getTime());
String folderNameMonth = formatMonth.format(date.getTime());
String folderNameDay = formatDay.format(date.getTime());
//創建年文件夾
File fileYear=new File(rootPath+"/"+folderNameYear);
if (!fileYear.exists()&&!fileYear.isDirectory()) {
fileYear.mkdir();
}

//創建月文件夾
File fileMonth=new File(rootPath+"/"+folderNameYear+"/"+folderNameMonth);
if (!fileMonth.exists()&&!fileMonth.isDirectory()) {
fileMonth.mkdir();
}
String path="/"+folderNameYear+"/"+folderNameMonth+"/"+folderNameDay;
File fileDay=new File(rootPath+path);
if (!fileDay.exists()&&!fileDay.isDirectory()) {
fileDay.mkdir();
}
return  path;
}
public static void main(String[] args) {
String rootPath="/you";
String folder = PlistUtil.createFolder(rootPath);
System.out.println(folder);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章