Look up a resource by name, and open an InputStream for reading it.
Look up a resource by name, and open an InputStream for reading it.
Name of the resource to search for.
InputStream for reading the found resource, if a resource was found.
Look up class resource files.
Look up class resource files.
This Resource looks up resources from the given Class,
using Class#getResource.
For example, if classOf[com.example.ExampleClass]
is given for clazz
, then resource files will be searched for
in the com/example
folder containing ExampleClass.class
.
If you want to look up resource files relative to the call site instead (that is, you want your class to look up one of its own resources),
use the my
method instead.
The class to look up from.
A Resource for clazz
.
Resource.at(Class.forName("your.AppClass")).url("config.properties")
In this example, a file named config.properties
is expected to appear alongside the file AppClass.class
in the package your
.
Look up class resource files.
Look up class resource files.
This Resource looks up resources relative to the JVM class file for T
,
using Class#getResource.
For example, if com.example.ExampleClass
is given for T
, then resource files will be searched for in the com/example
folder containing ExampleClass.class
.
If you want to look up resource files relative to the call site instead (that is, you want a class to look up one of its own resources), use the my
method instead.
The class, trait, or object to look up from. Objects must be written with a .type
suffix, such as Resource.at[SomeObject.type]
.
A Resource for T
.
Resource.at[YourClass].url("config.properties")
Look up resource files using the specified ClassLoader.
Look up resource files using the specified ClassLoader.
This Resource looks up resources from a specific ClassLoader. Like the default Resource, resource names are relative to the root package.
ClassLoader to look up resources from.
A Resource that uses the supplied ClassLoader.
Resource.from(appClassLoader).url("com/example/config.properties")
Same as asStream but throws a NoSuchElementException if resource is not found
Same as asStream but throws a NoSuchElementException if resource is not found
Get URL of given resource A default argument of empty string is provided to conveniently get the root resource URL using {{Resource.getUrl()}}
Get URL of given resource A default argument of empty string is provided to conveniently get the root resource URL using {{Resource.getUrl()}}
Look up own resource files.
Look up own resource files.
This Resource looks up resources from the Class surrounding the call,
using Class#getResource.
For example, if my
is called from com.example.ExampleClass
,
then resource files will be searched for in the com/example
folder containing ExampleClass.class
.
A Resource for the call site.
Resource.my.url("config.properties")
Look up a resource by name, and get its URL.
Implementations of Resource.
This object itself is a Resource uses the current thread's context class loader. It also creates Resources with different lookup behavior, using the methods
at
,from
, andmy
.at
searches rom a Class,from
searches from a different ClassLoader, andmy
searches from the class, trait, or object surrounding the call.ClassLoader#getResource
Class#getResource
Different ways of loading a file as an InputStream
Resource