加油,新时代打工人!
package com.fqpais.web.controller.business;
import java.io.File;
import java.time.YearMonth;
/**
* @author wh
* @date 2024年06月24日9:23
*/
public class CreateFolderByYearMonth {
public static void main(String[] args) {
// 获取当前年月
YearMonth yearMonth = YearMonth.now();
int year = yearMonth.getYear();
int month = yearMonth.getMonthValue();
// 构建文件夹路径
String folderPath = "path/to/parent/folder/" + year + "-" + String.format("%02d", month) + "/";
// 创建文件夹
File folder = new File(folderPath);
if (!folder.exists()) {
if (folder.mkdirs()) {
System.out.println("Folder created successfully: " + folderPath);
} else {
System.err.println("Failed to create folder: " + folderPath);
}
}
}
}