Skip to content

Instantly share code, notes, and snippets.

@hishidama
Created October 1, 2011 17:06
Show Gist options
  • Save hishidama/1256333 to your computer and use it in GitHub Desktop.
Save hishidama/1256333 to your computer and use it in GitHub Desktop.
ScalaのREPLの仮想ディレクトリー内のファイルを保存するスクリプト
:power
import java.io._
import scala.tools.nsc.io.AbstractFile
def save(af: AbstractFile, dir: File) {
val f = new File(dir, af.name)
if (af.isDirectory) {
f.mkdirs()
af.par.foreach(a => save(a, f))
} else {
val buf = new Array[Byte](1024)
val is = af.input
try {
val os = new FileOutputStream(f)
try {
var len = 0
do {
len = is.read(buf)
if (len > 0) os.write(buf, 0, len)
} while(len >= 0)
} finally os.close()
} finally is.close()
}
}
save(intp.virtualDirectory, new File("D:/temp/scala/repl"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment