如何验证 javafx 图像的路径

How can I validate the Path for a javafx image

我想检查我的带有已定义路径的 javafx 图像是否存在。 如果文件系统中不存在 jet,我不想加载它。 但要做到这一点,我必须先检查路径。 我需要知道是否有验证它的功能。

这是我要创建图像的构造函数:

public TestController(String title){
    this.model = title;
    this.modelurl = "images/Test/"+model+"/uebersicht.png";
    this.farbImg = new Image(modelurl, 1500, 900, true, true);
}

有人知道这样做的好方法吗?

try{
  this.farbImg = new Image(modelurl, 1500, 900, true, true);
} catch (Exception e){ //Change the "Exception" class by the adequate exception
  //URL Not valid or whatever exception it caught
  //Do something
  System.out.println("Exception thrown  :" + e);
}

虽然我这里没有 IDE 来测试,但我认为这将是一个 IOException。