Reading a resource file in Spring boot
Some applications store XML files in src/main/resources folder and want to access it from a java class, using the following syntax
InputStream ioStream = Application.class.getResourceAsStream("template.xml");
But it returns a null object.
The problem with spring boot webapp is the file is actually a classpath resource. To access it use the following syntax
InputStream ioStream = Application.class.getClassLoader().getResourceAsStream("template.xml");
InputStream ioStream = Application.class.getResourceAsStream("template.xml");
But it returns a null object.
The problem with spring boot webapp is the file is actually a classpath resource. To access it use the following syntax
InputStream ioStream = Application.class.getClassLoader().getResourceAsStream("template.xml");
Comments
Post a Comment