Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newtoncalegari/0d9164d555636630e1a5c0dfd2635f5d to your computer and use it in GitHub Desktop.
Save newtoncalegari/0d9164d555636630e1a5c0dfd2635f5d to your computer and use it in GitHub Desktop.
criando_arquivo_android
// criar as funcoes para ler e escrever
fun escreverArquivo(context: Context) {
val filename = "nome_plantinha.txt"
val fileContent = "Plantinha do Pedro"
context.openFileOutput(filename, Context.MODE_PRIVATE).use {
it.write(fileContent.toByteArray())
}
}
fun lerArquivo(context: Context): String {
val filename = "nome_plantinha.txt"
val file = File(context.filesDir, filename)
val contents = file.readText()
return contents
}
// chamar as funcoes de leitura e escrita
escreverArquivo(this@MainActivity)
val txt_do_arquivo = lerArquivo(this@MainActivity)
val textView = findViewById<TextView>(R.id.textView)
textView.text = txt_do_arquivo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment