I want to read the file during runtime in Kotlin function, the file I want to read is stored
at projectname/app/credentials.json
and I want to read credentials.json
.
similar case can be how firebase read its credential file google-services.json
PS: I don’t want to put file in assets as I have already figured assets method
3
Answers
You can find your answers through this link
https://stackoverflow.com/a/62878278/21735165
You have to put the file into your assets folder and read it. Check out the link
In Kotlin, you can read a file from the filesystem using standard Java I/O operations. Here is a way you can read the "credentials.json" file located in your project directory:
Run this code :
Adjust the filePath variable to the correct relative path based on your project structure. This code will read the contents of "credentials.json" and return it as a string and if the file doesn’t exist, it will return null values.