Android Develop Data Save
Save data to file save data // This function will save the data of inputText into file "data" as text file // The file "data" will be saved to /data/data/com.aimerneige.example/files/data fun save(inputText: String) { try { // "data" is the name of the file you saved on phone storage // You can change it as you want val output = openFileOutput("data", Context.MODE_PRIVATE) val writer = BufferedWriter(OutputStreamWriter(output)) writer.use { it.write(inputText) } } catch (e: IOException) { e.printStackTrace() } } load data // This function will try to load the data at a file named "data" // which is on /data/data/com.aimerneige.example/files/data fun load(): String { // a StringBuilder to load data val content = StringBuilder() try { // "data" is the name of the file you want to find on disk val input = openFileInput("data") val reader = BufferedReader(InputStreamReader(input)) reader.use { reader.forEachLine { content.append(it) } } } catch (e: IOException) { e.printStackTrace() } return content.toString() } You can also use like this: ...