Groovy缺少方法异常:没有`java.lang.String.getFileSystem()`方法的签名。

huangapple go评论70阅读模式
英文:

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&#39;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>



huangapple
  • 本文由 发表于 2020年9月29日 23:50:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64123177.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定