java - Why use getResourceAsStream when loading images? -


let's i'm creating jar file , have icon in asset folder included in jar.

so before using, stage.geticons().add(icon); in code there particular advantage or disadvantage having icon

image icon = new image("assets/icon.png"); 

vs.

image icon = new image(getclass().getresourceasstream("assets/icon.png")); 

both seem work fine, i'm looking pinpoint should gravitate towards , why.

there's related topic here compares loading styles web applications.

javafx.scene.image(string) calls validateurl, additional processing of string value, including checking current threads contextclassloader resource.

the advantage of using class#getresourceasstring you've made decisions class, (slightly) faster, less ambiguous , easier diagnose should have issues (as control source mechanism image itself) , aren't leaving decision making code don't control (and since validateurl private static, can't change)


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -