Package com.github.ngoanh2n
Class Resources
java.lang.Object
com.github.ngoanh2n.Resources
Find and read Java resources.
-
Field Summary
Modifier and TypeFieldDescriptionIndicate to find the resource file on classpath.
Default totrue
. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getContent
(String resourceName) Get the resource file asString
.static String
getContent
(String resourceName, Charset charset) Get the resource file asString
.static File
Get the resource file.static InputStream
getInputStream
(String resourceName) Get the resource file asInputStream
.static Path
Get the path of resource.
-
Field Details
-
findOnClasspath
Indicate to find the resource file on classpath.
Default totrue
.true
: Look for the resources on the classpath.
[PROJECT]/out/test/resources/ or [PROJECT]/out/production/resources/false
: Look for the resources in root location.
[PROJECT]/src/test/resources/ or [PROJECT]/main/test/resources/
-
-
Method Details
-
getFile
Get the resource file.- Parameters:
resourceName
- is the name of resource.
e.g. com/foo/File.properties- Returns:
File
of resource if the file exists;RuntimeError
otherwise.
-
getPath
Get the path of resource.- Parameters:
resourceName
- is the name of resource.
e.g. com/foo/File.properties- Returns:
Path
of resource if the file exists;RuntimeError
otherwise.
-
getInputStream
Get the resource file asInputStream
.- Parameters:
resourceName
- is the name of resource.
e.g. com/foo/File.properties- Returns:
InputStream
if the file exists;RuntimeError
otherwise.
-
getContent
Get the resource file asString
.- Parameters:
resourceName
- is the name of resource.
e.g. com/foo/File.properties- Returns:
String
if the file exists;RuntimeError
otherwise.
-
getContent
Get the resource file asString
.- Parameters:
resourceName
- is the name of resource.
e.g. com/foo/File.propertiescharset
- the charset to use, null means platform default.- Returns:
String
if the file exists;RuntimeError
otherwise.
-