简体   繁体   English

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

[英]How can I read text in a file path in Java Spring Boot?

I'm using Java Spring Boot to build a simple desktop app and there, in the following constructor for the class EmailSenderHandler I want to set this.emailBody property to the text content in the HTML file stored in htmlFilePath .我正在使用 Java Spring Boot 构建一个简单的桌面应用程序,在 class EmailSenderHandler的以下构造函数中,我想将this.emailBody属性设置为存储在htmlFilePath中的 HTML 文件中的文本内容。 I can't think of a proper method to do that, can anyone help me with that?我想不出一个合适的方法来做到这一点,任何人都可以帮助我吗? Thanks in advance.提前致谢。

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;
    }

I think you might want to utilize a character input stream to read the html file and add to the mail body string.So first of all you create new File(htmlFilePath) then you apply a new instance of character stream with the file in the constructor.我想你可能想利用字符输入 stream 来读取 html 文件并添加到邮件正文字符串中。所以首先你创建new File(htmlFilePath)然后你应用一个新的字符实例 stream 与构造函数中的文件.

Maybe you can read the body later,也许你可以稍后阅读正文,


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);
    }

and implement the readEmailBodyFromHtml method并实现readEmailBodyFromHtml方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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