How to read a text file from resources in Kotlin?

后端 未结 10 577
心在旅途
心在旅途 2020-12-08 17:59

I want to write a Spek test in Kotlin. The test should read an HTML file from the src/test/resources folder. How to do it?

class MySpec : Spek({         


        
10条回答
  •  孤城傲影
    2020-12-08 18:53

    You might find the File class useful:

    import java.io.File
    
    fun main(args: Array) {
      val content = File("src/main/resources/input.txt").readText()
      print(content)
    } 
    

提交回复
热议问题