javaspring-boottomcatfilenotfoundexceptionweb-inf

Error Caused by: java.io.FileNotFoundException for file under src/main/resources/config/env/dev2 in SpringBoot 2.0 application


BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(propertyFile))));

Here I have tried giving propertyFile as both "/envsettings/xdev2/env.properties" and "envsettings/xdev2/env.properties" but still getting same file Not found issue.

When I see the directory structure I see C:\Users\primary\git\dev\SpringBoot\Originations\target\odyssey\WEB-INF\classes\config75\envsettings\dev2\env.properties

can anyone help please?


Solution

  • Never access the resources from the classpath like that. Use Class.getResourceAsStream or ClassLoader.getResourceAsStream:

    BufferedReader br = new BufferedReader(
        this.getClass().getResourceAsStream("path/relative/to/classpath/resource.file")
    );