https://kotlinlang.org logo
#android
Title
# android
k

KV

12/01/2019, 2:27 PM
Hi Guys, I am facing an issue while writing the data (Append the data) into raw (demofile.txt) folder. I am able to read the data but the I can’t append the data. My Reading functionality is looking like this from raw folder
Copy code
fileContent = readFileFromRawDirectory(R.raw.demoFile) . ---> This is the file inside the /raw folder

private fun readFileFromRawDirectory(resourceId: Int): String {
        val iStream: InputStream = context?.resources.openRawResource(resourceId)
        var byteStream: ByteArrayOutputStream? = null
        try {
            val buffer = ByteArray(iStream.available())
            iStream.read(buffer)
            byteStream = ByteArrayOutputStream()
            byteStream.write(buffer)
            byteStream.close()
            iStream.close()
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return byteStream.toString()
    }
Now I want to add the data inside the same demoFile.txt This below code is for writing the string inside the demoFile.txt
Copy code
private fun writeDataIntoFile(searchText: String) {
        val file = context?.filesDir?.absolutePath + "/demoFile.txt"
        try {
            val fileout: FileOutputStream? = context?.openFileOutput(file, MODE_PRIVATE)
            val outputWriter = OutputStreamWriter(fileout)
            outputWriter.write(searchText)
            outputWriter.close()
            fileout?.close()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
stackoverflow 5
I tried the above code from stack overflow it self but still don’t get any working solution.
r

rkeazor

12/01/2019, 2:59 PM
this channel is for kotlin based android questions. your question is outside the scope of this channel
k

KV

12/01/2019, 3:05 PM
@rkeazor Opss .. sorry 🙏 then may I know the correct channel ?
r

rkeazor

12/01/2019, 3:21 PM
Kotlinlang is all Kotlin based. Try Android united slack workspace
k

KV

12/01/2019, 3:21 PM
sure thanks
r

rkeazor

12/01/2019, 3:21 PM
4 Views