Skip to content
𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

Reading file from resources folder

Posted on September 19, 2020December 10, 2023 By sastrija

Below code can be used to read the files from resources folder of a Spring Boot application.

InputStream is = MyClass.class.getResourceAsStream(PATH_TO_RESOURCE_FILE);

For example:

InputStream is = MyClass.class.getResourceAsStream("/static/pdf/Test.pdf");

If you are using JDK 8+, then it is best practice to use this along with try.

try (InputStream is = MyClass.class.getResourceAsStream(PATH_TO_RESOURCE_FILE)) {
    // Your code to process the file
}

Related

Java/J2EE Spring Boot Best PracticesExamplesJ2EEJavaSpringSpring BootSpring Framework

Post navigation

Previous post
Next post
©2026 𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ | WordPress Theme by SuperbThemes