Caleb Caleb - 1 year ago 92
Java Question

new File(path) or class.getResourses(path)?

BufferedImage image =;
BufferedImage image = File(path);

I've seen in couple of similar questions here before asking this, but I'm still confused a little.

I spent a bit of time reading java docs on those but it made the whole picture even more complex.

What do I need to use for uploading a resource in my program and what is the difference between the two?

Answer Source

SpriteSheet.class.getResource(path) finds the file that is in your java classpath.

new File(path) finds the file in anywhere on the file system

if your resource is in your classpath use class.getResource(path)