Answers for "read from file kotli"

0

kotlin read file

// In a list of lines
fun readFileAsLinesUsingReadLines(fileName: String): List<String> 
  = File(fileName).readLines()
// As a sole string
fun readFileDirectlyAsText(fileName: String): String 
  = File(fileName).readText(Charsets.UTF_8)
// Line by line
fun readFileLineByLineUsingForEachLine(fileName: String) 
  = File(fileName).forEachLine { println(it) }
Posted by: Guest on April-21-2021
0

read file kotlin

//internal storage
var fileInputStream: FileInputStream? = null  
fileInputStream = openFileInput(filename)  
var inputStreamReader: InputStreamReader = InputStreamReader(fileInputStream)  
val bufferedReader: BufferedReader = BufferedReader(inputStreamReader)  
val stringBuilder: StringBuilder = StringBuilder()  
var text: String? = null  
while ({ text = bufferedReader.readLine(); text }() != null) {  
    stringBuilder.append(text)  
}  
//Displaying data on EditText  
fileData.setText(stringBuilder.toString()).toString()
Posted by: Guest on November-15-2021

Browse Popular Code Answers by Language