import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class createfile {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int j,i,february;
System.out.println("请输入年份");
int year=sc.nextInt();
if ((year%4==0&&year%100!=0)||year%400==0){
february =29;
}else {
february =28;
}
int[] month={31,february,31,30,31,30,31,31,30,31,30,31};
for (i=1;i<=12;i++) {
File file = new File("D:/日记/"+year+"/"+year+"年"+i+"月");
//文件夹我放在D盘里
if (file.mkdirs()) {
System.out.println("文件夹创建成功");
}
}
for (j=1; j<=12; j++) {
for (i=1;i<=month[j-1];i++) {
File file2 = new File("D:/日记/"+year+"/"+year+"年"+j+"月", year+"年"+j+"月"+i+"号.txt");
try {
if (file2.createNewFile()) {
System.out.println("文件创建成功");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
文件放在D盘里