0

I have an instance of scala.reflect.io.Directory and I would like to use it as the working directory of a Process:

val workDirectory : scala.reflect.io.Directory = ???
Process("myCommand", workDirectory)

Process requires a Java java.io.File argument, however. How do I convert the scala Directory to a Java File? I can see methods like toFile, toAbsolute, ... but none of them returns what I need (the same applies for Scala File or Path).

Mifeet
  • 12,949
  • 5
  • 60
  • 108

1 Answers1

1

As there is no scaladoc for this class it is a bit hard to find how to use it, but came across this. Also on StackOverflow this.

Which leads to the following working (in a 2.11 REPL):

scala> import scala.reflect.io.Directory
import scala.reflect.io.Directory

scala> import java.io.File
import java.io.File

scala> val workDirectory : Directory = Directory(new File("~/temp"))
workDirectory: scala.reflect.io.Directory = ~/temp

scala> workDirectory.jfile
res0: java.io.File = ~/temp

NB: The link indicates that this is experimental and not really for external use. As such, it might not be the best API to be using, but if you have one for some reason and you have no other way to get an appropriate File then it seems the jfile attribute will return the underlying File.

Community
  • 1
  • 1
Mike Curry
  • 1,609
  • 1
  • 9
  • 12