read csv files from jar file

Hi all,

here is the code snippet

csv("/data/user_information.csv")

/data/user_information.csv is packed inside of jar file which is in classpath. Everything is built with sbt. Is there a way to read user_information.csv with csv function from jar file which is in classpath.

val path = getClass.getResource("/data/user_information.csv").getFile
val file:File = new File(new java.io.File(path))
csv(file)

that snippet does not work

Regards,
Yuri

The csv built-in currently locates the file on the file system, not in the classpath (but that’s an interesting use case, we might consider implementing it), so basically, the answer is: currently no.

Anyway, csv(file) only produces a Array[Map[String, String]] that’s implicitly converted into a feeder, so you can just copy SeparatedValuesParser logic in your snippet:
https://github.com/excilys/gatling/blob/1.4.X/gatling-core/src/main/scala/com/excilys/ebi/gatling/core/feeder/csv/SeparatedValuesParser.scala

Just use Source.fromInputStream instead of fromFile.

Cheers,

Stéphane