In our application, we are sending an email during registration.
For this we have got an email template stored under /usr/local/email.html
StringWriter writer = new StringWriter();
IOUtils.copy(new FileInputStream(new File("/usr/local/email.html")),writer);
message.setContent(writer.toString(), "text/html");
Transport.send(message);
The above is working fine .
We don't want to hardcode this path (/usr/local/email.html), wanted to keep under classpath
If I keep it under classpath how can I read it?
StringWriter writer = new StringWriter();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream is = loader.getResourceAsStream("email.html");
IOUtils.copy(is,writer);
message.setContent(writer.toString(), "text/html");
Transport.send(message);
With the above code, I'm getting a java.lang.NullPointerException at
IOUtils.copy(is,writer);