Scala IO 读写
package scala_learn.demo14_IO
import java.io._
import scala.io.Source
/**
* Created by liguohua on 2017/3/31.
*
*/
class O1_IODemo {
}
object O1_IODemo {
def main(args: Array[String]) {
}
def readOperate(filePath: String): Unit = {
val file1=Source.fromFile("d:/test.txt")
for (line<-file1.getLines()){
println(line)
}
file1.close()
val file2=Source.fromFile("d:/test.txt")
file2.foreach(print)
file2.close()
val file3=Source.fromURL("http://spark.apache.org")
for(line<-file3.getLines){
println(line)
}
}
def consoleTest(): Unit ={
println("请输入姓名")
val input = readLine()
println("你输入的内容是"+input)
}
def writeOperate(filePath: String): Unit = {
val writer = new PrintWriter(new File(filePath))
writer.write("Hello Scala")
writer.close()
println(writer)
}
}