JavaFX程序中,控件需要获取的路径参数,有以下3种方式:
1、类反射获取相对路径
Image image = new Image(getClass.getResource(pathStr).toString());
资源文件一般存放在 Project/out/production/Project 相应的文件夹中;
2、File对象获取相对路径
Image image = new Image("file:"+pathStr);
资源文件一般存放在 Project 根目录下 相应的文件夹中;
3、通过 http URL获取路径
Image image = new Image(httpURL);
获取文件的父目录路径
File file = new FIle(......);
//parentPath末端不带文件分隔符
String parentPath = file.getAbsoluteFile().getParent();