1

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;
    }
Nivin Viraj
  • 35
  • 1
  • 9
  • If it's on the same machine the program is running on you should read it the same way you read a file in any other java application. Or are you asking how it's done in java in general? – Federico klez Culloca Mar 29 '22 at 16:58
  • Yes I am asking how it is done in Java. And also yes it is stored locally in the machine. – Nivin Viraj Mar 29 '22 at 17:04
  • Does this answer your question? [Reading a plain text file in Java](https://stackoverflow.com/questions/4716503/reading-a-plain-text-file-in-java) – Federico klez Culloca Mar 29 '22 at 17:06

2 Answers2

0

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.

0

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

Kai-Sheng Yang
  • 1,535
  • 4
  • 15
  • 21