Skip to content
Rajesh R edited this page Jun 16, 2024 · 1 revision

Confused by the various ways to load resources in Java? Worry no more:

val resource        : InputStream   = Resource.getAsStream("foo.txt") //Same as this.getClass().getResource("foo.txt")
val resourceURL     : java.net.URL  = Resource.getUrl("foo.txt")
val rootResourceURL : java.net.URL  = Resource.getUrl()
val resourceAsStr   : String        = Resource.getAsString("foo.txt")

The above APIs can load from custom ClassLoaders too:

val resource        : InputStream   = Resource.at[MyClass].getAsStream("foo.txt")
Clone this wiki locally