繁体   English   中英

如何在 Java Spring Boot 中读取文件路径中的文本?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM