Open file through smart locale from a src modules

Hi, I’m a big noob, so I would like some kind help

In my intellij project, I’m trying to access and open an .sql file in a folder in src/main/kotlin. I do NOT want to open these files from the special resources folder.
I tried
val txt = File("./sql/CreateActivity.sql").readText(Charsets.UTF_8) But apparently, it doesn’t work with the smart dot. I also tried “src/main/kotlin/sql/CreateActivity.sql”

It gives me an exception. I tried looking in stack overflow but ALL I found was code to access resources or open file in the same directory as the file running the code… this is the most important point. Is there some regex to help it do some smart locale to find the file?

I want to do this because I have a folder with .sql, so I want to read it as a string file and give as input to functions to execute as sql statements.
Thanks!!!

Kotlin/Java is not a scripting language. The location of source files is irrelevant, because they are compiled and executed from a different place. Also, your sql file is totally ignored, it wouldn’t be even present in the resulting application, because it is placed in a wrong directory. There is a reason why there is a separate directory for resources.

You mentioned “special resources folder”, so I assume you already found some kind of a guide on how to do this properly. Then I suggest you to not try to be too much creative while you are still a “big noob” and just follow the instructions / documentation :slight_smile:

1 Like