java - Avoid full file paths when importing files -
trying read image java, have this:
image img = new image("file:e:/javaworkspace/project/src/resource/image.png");
however, not 1 going working on project , path works in machine. did try
image img = new image("file:/resource/image.png")
but leads filenotfound
. don't know thing called in english, hope understand trying convey here.
edit:
i added folder "resource" via build path , trying input stream such:
imageview imgview = new imageview(new image(this.getclass().getresourceasstream("/resource/image.png")));
needless say, nullpointerexception
, according documentation, occurs when path doesn't exist. how can not exist after created via build path, exists in classpath. (yes, file there or can not copy folder? )
place image inside project folder rather using file system access file. can use this:
image image = imageio.read(getclass().getresourceasstream("/resource/image.png"));
to image file ever required anyone.
Comments
Post a Comment