When I run my app in sbt console my-app/run
(my-app is a module), I get this error
java.io.FileNotFoundException: file:.../target/bg-jobs/sbt_eea980c4/job-3/target/aaa32a5e/b2227e4f/my-app_2.13-0.1.0-SNAPSHOT.jar!/my_file.csv
My directory structure is my-app->src->main->resources->my_file.csv
. The way I am accessing the file in my code is:
val file = new File(getClass.getResource("/my_file.csv").getPath)
What am I missing here?
CodePudding user response:
sbt stuck your resources in a jar, so you can't access them as a file. You can use getClass().getResourceAsStream("/my_file.csv")
instead.