0
    val jsonString_ = File("C:/Users/admin/Document/sample.json").readText()
    System.out.println(jsonString_)

    //or this
    val jsonString = applicationContext.assets.open("../res/sample.json")
        .bufferedReader()
        .use { it.readText() }

    System.out.println(jsonString)

I tried both codes but I get "No such file or directory" or "java.io.FileNotFoundException" errors.I tried Intellij, it worked but it doesn't work on android

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<application 
    android:requestLegacyExternalStorage="true"/>

I added them to the manifest file,nothing changed.

Arafin
  • 37
  • 6
  • 1
    Where are you running the code you mentioned? On your phone? – Julia Jan 04 '23 at 16:28
  • "but it doesn't work on android" -- `C:/Users/admin/Document/sample.json` is not a valid filesystem path on Android, and `"../res/sample.json"` is not a valid location inside your module's `assets/` directory. – CommonsWare Jan 04 '23 at 16:33
  • @Julia Emulator – Arafin Jan 04 '23 at 16:44
  • @CommonsWare "sample.json" or assets/sample.json" not work . assets file not found – Arafin Jan 04 '23 at 16:45
  • 1
    Where *exactly* in your project is `sample.json`? For example, `C:/Users/admin/Document/sample.json` is not going to be [inside of your project, in an `assets` directory that you create](https://stackoverflow.com/a/18302624/115145). – CommonsWare Jan 04 '23 at 17:05

0 Answers0