scala akka 修炼之路2(文件操作)

阅读更多

package cn.yangg.scala.base.init

 

object Start {

def main(args:Array[String]){

  valpath="/Users/yangguo/tool/mvn.ln"

  valurl="http://www.baidu.com"

   

  readDataUseJavaApi(path)

  readDataUseScalaApi(path)

 

  readDataFromUrl(url)

}

def readDataUseJavaApi(path:String){

  import java.io._

  val in=new FileInputStream(path)

  var buffer:Array[Byte]=new Array[Byte](1024)

  while(in.read(buffer)>0){

    println(buffer.length+","+new String(buffer,"utf8"))

  }

  in.close()

}

def readDataUseScalaApi(path:String){

  import scala.io.Source

  val data=Source.fromFile(path)

  data.getLines.foreach(println)

}

def readDataFromUrl(url:String){

  import scala.io.Source

  val data=Source.fromURL(url)

  data.getLines.foreach(println)

}

}

http://blog.csdn.net/yangguo_2011/article/details/28313983

你可能感兴趣的:(Akka)