Kamis, 28 Oktober 2021

How to Load Resources from Classpath in Java with Example

Classpath in Java is not only used to load .class files, but also can be used to load resources e.g. properties files, images, icons, thumbnails, or any binary content. Java provides API to read these resources as InputStream or URL. Suppose, you have a properties file inside the config folder of your project, and you want to load that properties file, how do you do that? Similarly, you have icons and thumbnails for your web applications on the icons directory of your project, how do you load them? The answer is by using java.lang.Class' getResource() and getResourceAsStream() method. These methods accept the path of resource as String and return URL and InputStream respectively.

Lorem ipsum is simply dummy text of the printing and typesetting industry.

Comments


EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)