I need to read a text file stored at src/main/assets/
i.e; in the assets folder and get it as a string.
Is there a simple way to do it.
Java copy, paste, convert functions are giving trouble, so I'd rather use a kotlin way.
I need a kotlin way to do this
Right click on the assets folder, select New >> file (myText. txt) and your text.
1) Select "Project" from the top of the vertical toolbar to open the project "tool window" 2) From the drop-down menu at the top of the "tool window", select "Android" 3) Right-click on "App" and select "New" then -> "Folder" (the one with the green Android icon beside it) then -> "Assets Folder" 4) Right-click on the ...
Step 1: To create an asset folder in Android studio open your project in Android mode first as shown in the below image. Step 2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder. Step 3: Android Studio will open a dialog box. Keep all the settings default.
I found this in a youtube video. Here is the link https://www.youtube.com/watch?v=o5pDghyRHmI
val file_name = "qjsonfile.json" val json_string = application.assets.open(file_name).bufferedReader().use{ it.readText() }
Saves the JSON or text to the string json_string
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With