Home > database >  FileNotFoundException exception when reading from a HTML resource
FileNotFoundException exception when reading from a HTML resource

Time:01-10

I try to open and read an HTML file from within class path.

Please find the directory structure in screenshot below

enter image description here

Inside class SendEmail class I want to read that verification.html file.

Code

When using the code below, it is throwing me a java.io.FileNotFoundException exception here:

emailContent = readHTMLFile("../emailTemplate/EmailVerificationTemplate/verification.html");

The readHTMLFile method looks like this:

public String readHTMLFile(String path) throws IOException {
    String emailContent = "";
    StringBuilder stringBuilder = new StringBuilder();
    BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
    while ((emailContent = bufferedReader.readLine()) != null) {
        stringBuilder.append(emailContent);
    }
    return stringBuilder.toString();
}

However, when I use an absolute path everything is working fine.

I am very new to Java world. Please help me to fix this

  •  Tags:  
  • Related