[英]How can I read text in a file path in Java Spring Boot?
我正在使用 Java Spring Boot 構建一個簡單的桌面應用程序,在 class 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;
}
我想你可能想利用字符輸入 stream 來讀取 html 文件並添加到郵件正文字符串中。所以首先你創建new File(htmlFilePath)
然后你應用一個新的字符實例 stream 與構造函數中的文件.
也許你可以稍后閱讀正文,
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
方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.