This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you really want to do it yourself instead of using a library like commons-io, you can do the following in version 2.8. Create a helper method "use". It will give you a form of automatic resource management. | |
def use[T <: { def close(): Unit }](closable: T)(block: T => Unit) { | |
try { | |
block(closable) | |
} | |
finally { | |
closable.close() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java 7 is now out and you have another option: java.nio.file.Files.copy. The probably easiest solution (And with Scalas superior import even easier). Provided that from and to are strings as in your question: | |
import java.nio.file.StandardCopyOption.REPLACE_EXISTING | |
import java.nio.file.Files.copy | |
import java.nio.file.Paths.get | |
implicit def toPath (filename: String) = get(filename) | |
copy (from, to, REPLACE_EXISTING) |
NewerOlder