Home > Blockchain >  How can I read text in a file path in Java Spring Boot?
How can I read text in a file path in Java Spring Boot?

Time:03-30

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

CodePudding user response:

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.

CodePudding user response:

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

  • Related