I need to read a Json file to load data into memory.
The project has the following structure of modules:
|_ app
|_ data
|_ datasource
|_ theory.json
|_ domain
I tried to save the json file into data module, and then in the datasource class I tried to read the file to be parsed by GSON library.
So I tried into a Kotlin class of the data module:
val fileInputStream = FileInputStream("theory.json")
val fileInputStream = FileInputStream("/theory.json")
val fileInputStream = FileInputStream("../theory.json")
And always I'm getting the this error:
theory.json: open failed: ENOENT (No such file or directory)
But I put the file in the assets folder of package app, and then I do:
|_ app
|_assets
|_ theory.json
|_ data
|_ datasource
|_ domain
val file = context?.assets?.open("theory.json")
Once I get the file I'm able to read the file and parse it with the Gson Library, so it works perfect.
The problem here is that to make the datasource work , I need to create the file into de app module, then start to pass it via params to datasource.
Is there any way to make it work "isolated" from the app module, and make it work in the data module?