获取资源目录的绝对路径而不引用其中的任何文件 - Scala?

Get Absolute Path of Resource directory without referring to any file within it - Scala?

我有 Java 背景,是 Scala 的新手。我尝试寻找在不引用其中任何文件的情况下找到资源目录绝对路径的方法,但答案是引用资源文件夹中存在的文件。

我尝试了以下方法但出现异常 (java.nio.file.InvalidPathException: Illegal char <:> at index 2)。

var resourceDirectory: java.nio.file.Path = null;
resourceDirectory = Paths.get(getClass.getResource(".").getPath)
resourceDirectory = Paths.get(getClass.getResource("/").getPath)
resourceDirectory = Paths.get(getClass.getResource("./").getPath)

如何在不引用其中包含的任何文件的情况下获取资源目录的绝对路径?

这里没有 API,因为资源通常与应用程序的 class 文件一起存储在 jar 文件中。在这种非常常见的情况下,您无法访问资源目录,因为没有资源目录。