How to do it...

  1. Import the File.separator constant and assign an alias to it:
import java.io.File.separator as SEPARATOR
  1. Declare a String storing a path to the file we are going to read:
val filePahtName = "src${SEPARATOR}main${SEPARATOR}resources${SEPARATOR}file1.txt"
  1. Instantiate a File using the specified path:
val filePahtName = "src${SEPARATOR}main${SEPARATOR}resources${SEPARATOR}file1.txt"
val file = File(filePahtName)
  1. Read the text from the file and print it to the console:
val filePahtName = "src${SEPARATOR}main${SEPARATOR}resources${SEPARATOR}file1.txt"
val file = File(filePahtName)
val fileText: String = file.readText()
println(fileText)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.19.253