英文:
groovy MissingMethodException: No signature of method: java.lang.String.getFileSystem()
问题
我正在尝试映射目录中的所有xml文件,就像这样:
```java
static Map<String, String> mapFilesInDirectory(Path dir) throws IOException {
Map<String, String> map = Files.find(dir, 0, (path, basicFileAttributes) -> basicFileAttributes.isRegularFile() && path.endsWith(".xml"))
.collect(Collectors.toMap(path -> path.getFileName().toString(), path -> ResourceUtils.getResourceAsString(path)));
return map;
}
并且我是这样调用该方法的:
def static importContentFromDirectory(String directoryName, String resourcePath, String importConfigurationFile = null) {
Path directoryPath = Paths.get(resourcePath + directoryName);
Map<String, String> map = mapFilesInDirectory(directoryPath);
importContentWithSeveralFiles(directoryName, map, importConfigurationFile);
}
当我调用mapFilesInDirectory时,我得到以下错误:groovy.lang.MissingMethodException: 找不到方法的签名:java.lang.String.getFileSystem() 适用于参数类型:() 值:[]
无法弄清楚原因。
<details>
<summary>英文:</summary>
I am trying to map all the xml files in a directory, like this:
static Map<String, String> mapFilesInDirectory(Path dir) throws IOException {
Map<String, String> map = Files.find(dir, 0, { path, basicFileAttributes -> basicFileAttributes.isRegularFile() && path.endsWith(".xml") })
.collect(Collectors.toMap({path -> path.getFileName()}, { path -> ResourceUtils.getResourceAsString(path) }
))
return map
}
And I am calling that method like this:
def static importContentFromDirectory(String directoryName, String resourcePath, String importConfigurationFile = null) {
Path directoryPath = resourcePath+directoryName as Path
Map<String, String> map = mapFilesInDirectory(directoryPath)
importContentWithSeveralFiles(directoryName, map, importConfigurationFile)
}
And I am getting this error when I call mapFilesinDirectory: groovy.lang.MissingMethodException: No signature of method: java.lang.String.getFileSystem() is applicable for argument types: () values: []
Can't figure it out.
</details>
# 答案1
**得分**: 1
这与我获取路径的方式有关。
我将以下内容更改为:
Path directoryPath = Paths.get(resourcePath+directoryName)
我现在的情况还不完全正确,但是那个特定的错误已经消失了。
<details>
<summary>英文:</summary>
It had to do with the way I was getting Path.
I changed the following:
Path directoryPath = resourcePath+directoryName as Path
To this:
Path directoryPath = Paths.get(resourcePath+directoryName)
What I have is still not quite right but that particular error is now gone.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论