How do I use Java getResource() to get a resource from a parent directory?

前端 未结 2 1318
执笔经年
执笔经年 2021-01-17 10:52

I\'ve tried numerous methods now, including FilenameUtils.normalize() from commons IO, but I can\'t seem to be able to get a resource in another folder to get a Java FXML fi

2条回答
  •  失恋的感觉
    2021-01-17 11:11

    It seems to me that if we use .getResource only when searching in marked as resource folder. Otherwise, even if folder path is correct, but it's not marked as resource folder we'll got an error. So, I do this way:

    FileInputStream fileInputStream = new FileInputStream(new File("src/main/java/CRUD/bnkseekCRUD.fxml"));
        Parent root = loader.load(fileInputStream);
    

提交回复
热议问题