Why public InputStream getResourceAsStream(String name) is in Class class? It just give inputstream of file which is in jar file and there is no relation with Class class. so it can be static method and it can be in any class.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
There is a relationship to the class:
getResourceAsStream("baz.txt")
on the class forfoo.bar.SomeClass
it will look for/foo/bar/baz.txt
Incorrect. Not all classloaders load resources from regular JAR file.
All of this complexity is hidden from you when you use the
ClassLoader
API viaClass
in this case.Incorrect. See @Jon Skeet's answer. Note that calling
Class.getResourceAsStream(String)
gives a resource that belongs to the same security context as the class. This can be very important if there are multiple classloaders / security contexts in use.