我正在使用Java Spring Boot构建一个简单的桌面应用程序,在下面EmailSenderHandler
类的构造函数中,我想将this.emailBody
属性设置为存储在htmlFilePath
中的HTML文件中的文本内容。我想不出合适的方法来做这件事,有人能帮我吗?提前谢谢。
public EmailSenderHandler(String inputFilePath,
String csvFilePath,
String htmlFilePath,
String fromEmail,
String password,
String fromEmailName,
String emailBody,
AtomicLong progressCount,
DataProcessor dataProcessor)
{
this.inputFilePath = inputFilePath;
this.csvFilePath = csvFilePath;
this.htmlFilePath = htmlFilePath;
this.fromEmail = fromEmail;
this.password = password;
this.fromEmailName = fromEmailName;
this.emailBody = emailBody;
this.progressCount = progressCount;
this.dataProcessor = dataProcessor;
}
也许你可以稍后阅读正文,
public EmailSenderHandler(String inputFilePath,
String csvFilePath,
String htmlFilePath,
String fromEmail,
String password,
String fromEmailName,
AtomicLong progressCount,
DataProcessor dataProcessor)
{
this.inputFilePath = inputFilePath;
this.csvFilePath = csvFilePath;
this.htmlFilePath = htmlFilePath;
this.fromEmail = fromEmail;
this.password = password;
this.fromEmailName = fromEmailName;
this.progressCount = progressCount;
this.dataProcessor = dataProcessor;
this.emailBody = readEmailBodyFromHtml(htmlFilePath);
}
并实现了readEmailBodyFromHtml
方法
我认为您可能希望使用字符输入流来读取html文件并添加到邮件正文字符串中。因此,首先创建new File(htmlFilePath)
,然后在构造函数中使用文件应用一个新的字符流实例。