Skip to content Skip to sidebar Skip to footer

Where Do I Have To Put My Txt File In Android Studio?

I'm trying to read a File from txt, but it's throwing a FileNotFoundException I already put it in the assets folder, and in the app folder but the exception is still there Here is

Solution 1:

I already put it in the assets folder

Use getAssets() on a Context to get an AssetManager. Call open("goodstops.txt") on the AssetManager to get an InputStream to use for reading in the contents of the asset.

Solution 2:

I use extension for AssetManager

fun AssetManager.readFile(fileName: String) = open(fileName)
  .bufferedReader()
  .use { it.readText() }

to read file:

valfileContent= context.assets.readFile("goodstops.txt")

Solution 3:

Place it in res/raw. Right click on res -> new -> Android Resource Directory -> Resource Type: raw

Post a Comment for "Where Do I Have To Put My Txt File In Android Studio?"