Kalle
Kalle

Reputation: 11

Creating json file in Internal Storage and writing on it

I am trying to create a Jsonfile inside the internal Storage of the App and then writing a jsonarray into it, but somehow it dosent create the file, i know this because i am trying to read it later on but it dosent work. Does anyone know why that is? My code looks like this:

fun addJson(){
            val dir = File(this.filesDir, "mydir")
            val json: String?
            try {
                val file =  File(dir,"stempel.json")
                val writer = FileWriter(file)

                val inputStream = assets.open("stempel.json")
                json = inputStream.bufferedReader().use { it.readText() }
                val jsonarr = JSONArray(json)

                writer.append(jsonarr.toString())
                writer.flush()
                writer.close()

            } catch (e: Exception){}
        }

``` 

Upvotes: 0

Views: 177

Answers (0)

Related Questions