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
  • 1,082,665
  • 372
  • 3,610
  • 3,555
dafodil
  • 531
  • 15
  • 30
  • 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
  • 15,741
  • 2
  • 40
  • 63
-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
  • 16,787
  • 19
  • 117
  • 151