0

I am working on a scala application. I have some files in my resouce folder of project. Those are json files. I want to load all of them as string and send them over to kafka topic. I already have kafka producer code but just don't know how to all files and send them. I am using following code

Source.fromResource(path_of_file).mkstring

But with this I am able to send only one file which I pass but how can I write a generic code to load them and send them one by one. This thing I need to do in BeforeAll of my cucumber test. In short I just want to send these files before my any scenario begin to execute

NikolaPi
  • 169
  • 1
  • 9
  • Did you have a look at the `java.nio.files` package and this https://docs.oracle.com/javase/8/docs/api/java/io/File.html? That could contian what you need. – Yann Jul 29 '20 at 07:24

1 Answers1

0

Which sbt version are you using? Please note that sbt 1.2.8 has a bug in listing directories. Otherwise the following should do that:

new File(getClass.getResource("/my-dir").getFile).listFiles().foreach(println)
Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
  • Just one more query. In intellij I am not getting the option of BeforeAll . Only Before and BeforeStep option available. I want to load these files at the starting of all of the test case not at every step. Do you know how I can do it? –  Jul 29 '20 at 09:38
  • Make sure you are importing org.scalatest.BeforeAndAfterAll, and extending BeforeAndAfterAll. It comes from the scalatest package, so make sure you import it at your build.sbt file. – Tomer Shetah Jul 29 '20 at 09:43
  • I added "org.scalatest" %% "scalatest" % "3.1.2" % Test, in my build.sbt. But still no BeforeAll option I am getting –  Jul 29 '20 at 11:56