愚蠢的新手问题。我可以使用
生成电子邮件正文email.setMsg("Paragraph 1 goes here.");
输出:
Paragraph 1 goes here.
现在我要生成的内容如下:
Paragraph 1 goes here.
Paragraph 2 goes here.
但如果我使用:
email.setMsg("Paragraph 1 goes here.");
email.setMsg("Paragraph 2 goes here.");
我得到的只是:
Paragraph 2 goes here.
如何添加手动换行符?
答案 0 :(得分:2)
假设您使用的是UNIX系统:
email.setMsg("Paragraph 1 goes here.\nParagraph 2 goes here.");
要使代码平台不可知,您可以使用System.getProperty("line.separator")
String ENDL = System.getProperty("line.separator");
email.setMsg("Paragraph 1 goes here." + ENDL + "Paragraph 2 goes here.");
如果您使用HTML电子邮件:
email.setMsg("<p>Paragraph 1 goes here.</p><p>Paragraph 2 goes here.</p>");