BufferedImage image;
image = ImageIO.read(SpriteSheet.class.getResourceAsStream(path));
I am currently making a 2D Java Game, as per an exercise in a course I am taking; however, there are a couple of things I do not understand here. The first thing I am not too sure about is:
SpriteSheet.class
I have never seen .class ever be used before. What exactly is it? Furthermore, why does just putting in path in the getResourceAsStream method work. Is it because I have the SpriteSheet in a res folder, which is in the program's build path.
Thank you for the help!
.class
refers to the Class
object for a given class.
for example, Integer.class
will refer to the Class
object for java.lang.Integer
.
getResourceAsStream()
will return an InputStream
pointing to a file in the current classpath.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.