I have searched over how to retrieve a file in Kotlin, and I found this code in Java.
public void load(View v) { FileInputStream fis = null; try { fis = openFileInput(FILE_NAME); InputStreamReader isr = new InputStreamReader(fis); BufferedReader br = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); String text; while ((text = br.readLine()) != null) { sb.append(text).append("\n"); } mEditText.setText(sb.toString()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } } How to write this in Kotlin Language...? So far by myself, I have tried to convert it in Kotlin but there are still some errors on some lines (denoted by ). Please help me in solving these errors.
var fis = File(FILE_NAME).inputStream //<ror>Unresolved reference File try { fis = openFileInput(FILE_NAME) var isr = InputStreamReader(fis) val br = BufferedReader(isr) val sb = StringBuilder() var text:List<String> = br.readLines() while ((text) != null) { //<ror> sb.append(text).append("\n") } mEditText?.text(sb.toString()) //<ror> } catch (e : FileNotFoundException) { e.printStackTrace() } catch (e : IOException) { e.printStackTrace() } finally { if (fis != null) { try { fis.close() } catch (e : IOException) { e.printStackTrace() } } }