I have a project structure like this:
src
|-main
|-java
|-com.abc.xyz
|-Login.java
I have to add a resource file to t
No..... the structure is wrong.... you should not create the same package under resources
, that is ugly and not proper: resources
is for resources, and should not contain source packages.
When using ClassLoader.getResources(asStream)(path)
method, the method just starts searching from the root of the classpath and the path name cannot start with /
as leading characters. What you have to do, is to mark the resources
as resources folder
in IntelliJ. Then the files under resources
will be listed under classpath and you can easily use them like you have done.
(I see in previous answers this option is not available yet in 2013, you only have mark as source folder
, just like in Eclipse till now we have "add source folder", but now in 2018 it is available in Intellij: you can mark a folder as source, resources, test source, test resources, and all of them will be add to the root of classpath. )