1

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?

GBouffard
  • 1,125
  • 4
  • 11
  • 24
Arijit
  • 47
  • 1
  • 8
  • The File constructor expects the path of a **file**, on the **file system**. The path can be absolute ("C:\Users\primary\git\dev\SpringBoot\Originations\target\odyssey\WEB-INF\classes\config75\envsettings\dev2\env.properties"), or relative to the current directory, i.e. the directory from where the java command was executed. Don't use file IO to read resources loaded fromthe classpath, and which will, in production at least, reside in the jar file of your app. Use `MyClass.class.getResourceAsStream("/config75/envsettings/dev2/env.properties")`. The javadoc is your friend. – JB Nizet Oct 09 '19 at 17:02
  • Could you add the project structure? Not the one from the **target** – Villat Oct 09 '19 at 17:03

1 Answers1

0

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")
);
madhead
  • 31,729
  • 16
  • 153
  • 201