我想计算放入使用此实现源代码包中的文件的路径:如何不硬编码的文件路径
URL pathSource = this.getClass().getResource("saveItem.xml");
当我试图创建类似下面的代码创建一个新文件:
File xmlFile = new File(pathSource.toString());
我试着用它来创建这样一个文件:
Document document = builder.parse(xmlFile);
这给我java.io.FileNotFoundException。 如何在没有硬编码的情况下计算文件路径?
PS:我已经使用了pathSource.getPath(),但它也不起作用。 我想用一个类似的实现:
FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
您是从一个罐子或从IDE中运行呢? – RealSkeptic