How to access test resources in Scala?

后端 未结 5 888
难免孤独
难免孤独 2020-12-04 07:58

I have a file data.xml in src/test/resources/.

How can I read that file into a new FileReader in my test data.scala

5条回答
  •  情歌与酒
    2020-12-04 08:26

    Another alternative (especially if you need to access resource as a File); is to obtain it's path via:

    val path = getClass.getResource("/testData.txt").getPath
    val file = new File(path)
    

    as has been pointed out in Scala get file path of file in resources folder

提交回复
热议问题