InputStream is null when trying to read a properties file in WEB-INF
<p>My <code>InputStream</code> object is making the console print out a NullPointerException whenever I try to read a properties file that is located in "/WEB-INF". But when I do <code>InputStream.toString()</code> it prints out <code>java.io.FileInputStream@1933968</code> instead of an actual <code>null</code> value.</p>

<p>Here is the stack trace that I'm getting back:</p>

<pre><code>SEVERE: Servlet.service() for servlet [spring] in context with path [/translator] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.webclaims.translator.TranslatorApi.readPropertiesFile(TranslatorApi.java:149)
at com.webclaims.translator.TranslatorApi.writePropertiesFile(TranslatorApi.java:128)
at com.webclaims.translator.controllers.TestController.editableWebpage(TestController.java:45)
</code></pre>

<p>The layout of <code>/WEB-INF</code>;</p>

<pre><code>WEB-INF-|
        |-jsp
        |-configDummy.properties
        |-spring-servlet.xml
        |-web.xml
</code></pre>

<p>I'm running this project on a Tomcat v8 server with Java 8.</p>

<p>spring-servlet.xml;</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;beans xmlns="http://www.springframework.org/schema/beans"    
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
xmlns:p="http://www.springframework.org/schema/p"    
xmlns:mvc="http://www.springframework.org/schema/mvc"   
xmlns:context="http://www.springframework.org/schema/context"    
xsi:schemaLocation="http://www.springframework.org/schema/beans    
                    http://www.springframework.org/schema/beans/spring-beans-4.3.xsd  
                    http://www.springframework.org/schema/mvc   
                    http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
                    http://www.springframework.org/schema/context    
                    http://www.springframework.org/schema/context/spring-context-4.3.xsd"&gt;

&lt;mvc:annotation-driven/&gt; 
&lt;context:component-scan base-package="com.webclaims.*" /&gt;
&lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
    &lt;property name="prefix" value="/WEB-INF/jsp/"&gt;&lt;/property&gt;
    &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id="propertiesFile" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
    &lt;property name="properties" value="/WEB-INF/configDummy.properties"&gt;&lt;/property&gt;
&lt;/bean&gt;
</code></pre>

<p></p>

<p>web.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"&gt;
  &lt;display-name&gt;translator&lt;/display-name&gt;

  &lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; 
    &lt;param-value&gt;/WEB-INF/spring-servlet.xml&lt;/param-value&gt; 
  &lt;/context-param&gt;
  &lt;listener&gt;
    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt; 
  &lt;servlet&gt;
    &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</code></pre>

<p>TestController.java(cotains the exceptions entry point)</p>

<pre><code>@Controller
@PropertySource("/WEB-INF/configDummy.properties")
public class TestController {

private static final Logger LOGGER = Logger.getLogger(TestController.class.getName());

private static final String PROPS_FILE = "/WEB-INF/configDummy.properties";

@RequestMapping(value = "/test")
public ModelAndView originalWebpage() {
    return new ModelAndView("testpage");
}

@CrossOrigin()
@RequestMapping(value = "/test", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String editableWebpage(@RequestBody String data, HttpServletRequest request) {
    InputStream inputStream = request.getSession().getServletContext()
            .getResourceAsStream(PROPS_FILE);
    System.out.println(inputStream);

    JsonParser parser = new JsonParser(data);
    Elements elements = parser.jsonToElements();
    TranslatorApi t = new TranslatorApi();
    t.writePropertiesFile(elements, inputStream);
    return data;
}
}
</code></pre>

<p>TranslatorApi.java</p>

<pre><code>@PropertySource("/WEB-INF/configDummy.properties")
public class TranslatorApi {

@Autowired
private Properties properties;

private static final Logger LOGGER = Logger.getLogger(TranslatorApi.class.getName());

public TranslatorApi() {}

public Properties getProperties() {
    return properties;
}

public void setProperties(Properties properties) {
    this.properties = properties;
}

public void writePropertiesFile(Elements elements, InputStream inputStream) {
    System.out.println("write opertion executed");
    System.out.println(elements);
    try {
        readPropertiesFile(inputStream);

        for(Element e : elements) {
            properties.setProperty(e.className(), e.text());
        }

        String path=Thread.currentThread().getContextClassLoader()
                .getResource("src/main/webapp/WEB-INF/props/configDummy.properties").toString();
        File file = new File(path);
        FileOutputStream fileOut = new FileOutputStream(file);
        properties.store(fileOut, "DUMMY");
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

private void readPropertiesFile(InputStream inputStream) throws IOException {
    try {
        properties.load(inputStream);
        inputStream.close();
    } catch(FileNotFoundException e) {
        LOGGER.log(Level.SEVERE, "FileNotFoundException has occured", e);
    } catch(IOException e) {
        LOGGER.log(Level.SEVERE, "IOException has occured", e);     
    } 
}
</code></pre>

<p>Most people on here recommend that I should put the properties file in the classpath. If I have it in there will I be able to write to it in the future?</p>