Home > Software design >  How to convert scala.io.BufferedSource to java.io.File?
How to convert scala.io.BufferedSource to java.io.File?

Time:11-17

I want to use the Apache POI library in a Scala project.

How can I convert a scala.io.BufferedSource type to a java.io.File type?

  val file = Source.fromResource("resource.file") // is type scala.io.BufferedSource
  // how can I do the conversion here
  val workbook = WorkbookFactory.create(file) // requires type java.io.File

This works, but I want to avoid specifying the folder path since the folder structure is handled by sbt convention:

  val file = new File("src/main/resources/resource.file")
  val workbook = WorkbookFactory.create(file)

Thank you for your time

  • Related