How to get the path of src/test/resources directory in JUnit?

前端 未结 14 1797
时光取名叫无心
时光取名叫无心 2020-11-28 01:25

I know I can load a file from src/test/resources with:

getClass().getResource(\"somefile\").getFile()

But how can I get the full path to th

14条回答
  •  时光取名叫无心
    2020-11-28 01:52

    If it's a spring project, we can use the below code to get files from src/test/resource folder.

    File file = ResourceUtils.getFile(this.getClass().getResource("/some_file.txt"));
    

提交回复
热议问题