Created
April 12, 2019 11:06
-
-
Save newtoncalegari/0d9164d555636630e1a5c0dfd2635f5d to your computer and use it in GitHub Desktop.
criando_arquivo_android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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