I'm trying to save some words contained in a variable text in a .txt file by clicking on a button . The drawback is that you should be saving a sequence of what you put in the variable text , but only save what you put it in the last execution.
var texto ="Registro 1"
btnInt.setOnClickListener(){
try {
val archivo = OutputStreamWriter(openFileOutput("notas.txt", Activity.MODE_PRIVATE))
archivo.write(texto)
archivo.flush()
archivo.close()
} catch (e: Exception) {
Toast.makeText(this,e.toString(),Toast.LENGTH_LONG).show()
}
}
If the text value changes in the next execution (var text="Record 2"), the expected result is that
appears in the "notes.txt" file.Record 1
Record 2
But, I reiterate, at this moment the value that is being expressed is that of the last execution
Record 2