提示:生成程序的需求文档,该程序允许公司通过电子邮件或邮政服务发送个性化邮件。模板文件包含消息文本以及变量字段(例如Dear [Title] [Last Name] ...)。数据库(存储为文本文件)包含每个收件人的字段值。使用HTML作为输出文件格式。然后设计并实施程序。
例如:
- [标题],[姓氏]
- 夫人,亚当斯
早上好[标题] [姓氏]。
public static void main(String[] args) throws FileNotFoundException {
// Inputting Template and Database
File template = new File("D:\\Documents\\Java\\MiniProject\\template.txt");
File database = new File("D:\\Documents\\Java\\MiniProject\\database.txt");
Scanner temp = new Scanner(template);
Scanner data = new Scanner(database);
//Console OutPut of the template file
while(temp.hasNextLine()){
System.out.println(temp.nextLine());
}
// HTML OutPut File
try {
PrintWriter output = new PrintWriter("output.html", "UTF-8");
output.println("<!DOCTYPE html>");
output.println("<html>");
output.println("<head>");
output.println("</head>");
output.println("<body>");
output.println("<p>");
// While loop to iterate the Template into an HTML File (Doesn't work)
while(temp.hasNextLine()){
output.println(temp.nextLine());
}
output.println("</p>");
output.println("</body>");
output.println("</html>");
output.close();
} catch (Exception e) {
}
}
我还没有弄清楚如何用数据库中的名称替换[Name]标记。使此提示更易于理解的任何方法都会有很大帮助。