java,如何批量创建有不同内容的 不同名文件

需求:批量创建文件,文件名:日期+序号,文件内容为数字,按照文件序号依次递增。
求解~


import java.util.Date;

/**
 * @author wangfei
 * @version 1.0
 * @date 2022/2/16
 */
public class CreateFilesTest {

    public static void main(String[] args) throws Exception{
        String path = "D:\\test";
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }

        Date date = new Date();
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HHmmss");
        String now = s.format(date);
        for (int i=0;i<10;i++) {
            String fileName = now + "_" + i;
            path = path + "\\" + fileName + ".txt";
            file = new File(path);
            file.createNewFile();
            OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "GBK");

            writer.write(i + "");
            writer.flush();
            writer.close();
            path = "D:\\test";
        }

    }
}

img

img

for循环创建不行吗?