0

I am trying to read an .html file from war file. I have used the code below, but it does not work.

Project structure:

Project
|_war
    |_Pages
      |_HtmlFiles
        |_sample.html

My code:

InputStream inputStream = EmailMessages.class.getClassLoader()
        .getResourceAsStream("/sample.html");
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
dafodil
  • 511
  • 10
  • 28
  • try getContext().getResourceAsStream("/_Pagestest/_HtmlFiles/_sample.html"); – Vickyexpert Jun 07 '16 at 10:23
  • Please don't use [java] tag as long as problem is not demonstratable using plain Java application class with main() method, nor is answerable with the JLS. You will only get knee-jerk "answers" from users/plagiarists who think to be good at Googling. – BalusC Jun 07 '16 at 11:15

2 Answers2

1

The root folder is on the classpath, so try this one:

this.getClass().getResourceAsStream("/Pages/HtmlFiles/sample.html");
meskobalazs
  • 14,510
  • 2
  • 33
  • 55
-1

Place you files in src\main\resources folder and when you export a war you can find your files in the resources directory under WEB-INF\classes folder. Now read the html file like this,

InputStream in = this.getClass().getResourceAsStream("/Pages/html/index.html");
Lucky
  • 14,677
  • 16
  • 104
  • 145