获取一月中最大的天数:yearMonth.lengthOfMonth();
public static void test002() throws IOException {
// 定义年
int year = 2024;
String path ="C:\\Users\\computer\\Desktop\\2years\\"+year;
// 定义12个月份
for(int month=1;month<=12;month++){
YearMonth yearMonth = YearMonth.of(year, month);
// 获取一月中最大的天数
int days = yearMonth.lengthOfMonth();
String filename="";
if(month<10){
filename = filename+ "0"+month;
}else {
filename = filename+ month;
}
for(int i=1;i<=days;i++){
String fileName002=filename;
if(i<10){
fileName002 = fileName002+ "0"+i;
}else {
fileName002 = fileName002+ i;
}
fileName002 +=".txt";
// 创建文件并写入
Files.write(Paths.get(path+fileName002),(path+fileName002).getBytes());
System.out.println(path+fileName002);
}
}
}