Vasanth Subramanian
Vasanth Subramanian

Reputation: 1351

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

I am from Java background and new to Scala. I tried searching for ways to find the resource directory absolute path without referring to any file within it, but answers were of referring to a file present within resources folder.

I tried below ways but got exception (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)

How to get the Absolute path of resources directory without referring to any files it contains?

Upvotes: 0

Views: 863

Answers (1)

Matthias Berndt
Matthias Berndt

Reputation: 4587

There is no API for this because resources are usually stored in a jar file along with the application's class files. In this very common case you can't access the resource directory because there isn't one.

Upvotes: 1

Related Questions