Created
October 1, 2011 17:06
-
-
Save hishidama/1256333 to your computer and use it in GitHub Desktop.
ScalaのREPLの仮想ディレクトリー内のファイルを保存するスクリプト
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
: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