對於那些不熟悉阿卡:
import java.io.{File, PrintWriter}
import akka.actor.{Actor,ActorSystem,Props}
object AkkaWriterExample extends App{
val outputPath : String = ???
val system = ActorSystem("WriterSystem")
val writer = system.actorOf(Props(new WriterActor(new File(outputPath))), name="writer")
writer ! "this is a test"
system.shutdown()
system.awaitTermination()
}
class WriterActor(outFile: File) extends Actor {
val writer = new PrintWriter(outFile)
// this is how you implement an akka actor
// plain scala actors look a bit different
def receive = {
case str:String => println(str); writer.write(str);
}
override def postStop() = {
writer.flush();
writer.close();
}
}
線()在scalax.io的是懶洋洋地評估 也可以看看在未來的高管HTTP:// jesseeichar.github.com/scala-io-doc/0.4.0/index.html#!/core/future_exec – oluies 2012-07-21 07:01:42