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

Time:12-07

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?

CodePudding user response:

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.

  • Related