java - Cannot read file with same URL and same file structure on different computer -
so wrote small application uses string represents filepath can create file , buffered image. have omitted irrelevant code example:
public class morphimage { private final string url0 = "pic1.jpg"; //.... url url = getclass().getresource(url0); file file = new file(url.getpath()); bufferedimage img = imageio.read(file);
my file structure follows:
projectname src package1 morphimage.java pic1.jpg
on laptop running windows 10, works fine, using exact same project on windows 8 pc, iioexception: can't read file!
on last row. both computers use same eclipse version , same jdk version. i'm not sure here. have tried many different filepaths on windows 8 machine throws np instead, path correct.
edit: solution below:
url defaultimage = morphimage.class.getresource(url0); file file = new file(defaultimage.touri()); bufferedimage img = imageio.read(file);
try resource stream ,with file path below
getclass().getclassloader().getresourceasstream("package1/pic1.jpg");
Comments
Post a Comment