OOP2019-00-创建Markdown格式的日报
java源程序如下:
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 运行方式: java -jar 本打包文件名.jar 年 月 本月天数
* @author subo
*/
public class Main {
public static void main(String[] args) {
int year = Integer.parseInt(args[0]);
int month = Integer.parseInt(args[1]);
int day = Integer.parseInt(args[2]);
createDayReport(year, month, day);
}
private static void createDayReport(int year, int month, int day) {
String yearString = "" + year;
String monthString = month < 10 ? "0" + month : "" + month;
String fileName = "工作计划" + yearString + "年" + monthString + "月.md";
StringBuilder contentBuilder = new StringBuilder();
contentBuilder.append("#").append(fileName).append("\n");
contentBuilder.append("##年度目标").append("\n");
contentBuilder.append("##本月目标").append("\n");
contentBuilder.append("##本月总结").append("\n");
for (int i = 1; i <= day; i++) {
String dayString = i < 10 ? "0" + i : "" + i;
contentBuilder.append("##").append(yearString).append(monthString).append(dayString).append("\n");
contentBuilder.append("- 目标:\n");
contentBuilder.append("- 思路:\n");
contentBuilder.append("- 计划:\n");
contentBuilder.append("- 行动:\n");
contentBuilder.append("- 成果:\n");
contentBuilder.append("- 问题:\n");
}
createMarkdownFile(fileName, contentBuilder.toString());
}
public static boolean createMarkdownFile(String fileName, String content) {
try (FileOutputStream fileOutput = new FileOutputStream(fileName, false);) {
fileOutput.write(content.getBytes());
} catch (IOException ex) {
ex.printStackTrace();
return false;
}
return true;
}
}
源程序和打包好的jar文件保存在网盘
https://pan.baidu.com/s/1l4ocZwgDtISBS7MyRdp_gg
下载其中的dayreport-1.0-SNAPSHOT.jar文件, 然后参考以下运行示例.
运行示例:
java -jar dayreport-1.0-SNAPSHOT.jar 2018 12 31
这篇博客介绍了如何在OOP2019年中利用Java编写程序,生成Markdown格式的日报。提供了源代码和打包后的jar文件下载链接,用户可以参照运行示例进行操作。

430

被折叠的 条评论
为什么被折叠?



