Answer the question
In order to leave comments, you need to log in
Which class to use in an expression like Class.getClassLoader().getResourceAsStream()?
There is a code:
class ThisClass {
void foo() {
InputStream resourceAsStream = ThisClass.class.getClassLoader().getResourceAsStream(path);
//...
}
}
class ThisClass {
void foo() {
InputStream resourceAsStream = ForeignClass.class.getClassLoader().getResourceAsStream(path);
//...
}
}
Answer the question
In order to leave comments, you need to log in
No difference. Almost always, the getClassLoader() method will return the same loader for any class in your application. Also, it is easier and shorter to use the getClass().getResourceAsStream(path)
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question