Load image from a filepath via BufferedImage

前端 未结 5 1108
耶瑟儿~
耶瑟儿~ 2020-12-20 12:01

I have a problem with Java application, particular in loading a image from a location in my computer.

Following this post I used a BufferedImage and a <

5条回答
  •  醉酒成梦
    2020-12-20 12:51

    getResource & getResourceAsStream do not work with file paths, but paths relative the code base. If the code base is C: then a relative path that would locate the resource is /ImageTest/pic2.jpg.

    ..difference between load file by FileInputStream and getResourceAsStream?

    One major difference is that the getResource.. will work with a resource inside a Jar, which is no longer a File. Therefore FileInputStream cannot be used to access such a resource.

提交回复
热议问题