How to read a text file from resources in Kotlin?

后端 未结 10 564
心在旅途
心在旅途 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:31

    Using Google Guava library Resources class:

    import com.google.common.io.Resources;
    
    val fileContent: String = Resources.getResource("/html/file.html").readText()
    

提交回复
热议问题