0

I wrote a class in src/main/java/com/xxx/service/impl, and loaded a properties file by using class.getClassLoader().getResourceAsStream(). The method looked up the file in src/main/resources but not in src or the project directory, why? What's the difference between folder and package?

  • See also: https://stackoverflow.com/questions/1464291/how-to-really-read-text-file-from-classpath-in-java/1464366#1464366 – lexicore Jun 27 '18 at 09:24

1 Answers1

1

getResourceAsStream() looks into the classpath that was provided to the program at runtime. Classpath is a collection of "places" where the program is allowed to look for its constituents, like classes or resource files.

A package is just a folder that happens to be in your application's classpath.

kumesana
  • 2,495
  • 1
  • 9
  • 10