簡體   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