Getting File from .jar using .getResource()

前端 未结 2 1156
礼貌的吻别
礼貌的吻别 2021-01-27 19:21

I\'m trying to acces a File inside the .jar. In Netbeans, this:

System.out.println(new File(this.getClass().getResource(\"Image.jpg\").getFile()).exists());
         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-27 20:24

    The file is packed, try

    resource.getInputStream() 
    

    or

    InputStream streamOfYourImg = this.getClass().getRessourceAsStream("com/package/resources/image.jpeg");
    

    Hope it helps

提交回复
热议问题