输入
scala> import scala.io.StdIn._
import scala.io.StdIn._
scala> val a = read
readBoolean readByte readChar readDouble readFloat readInt readLine readLong readShort
scala> val a = readInt()
a: Int = 1212
格式化输出
scala> val i = 5
i: Int = 5
scala> val f = 2.1
f: Double = 2.1
scala> val s = "Hello"
s: String = Hello
scala> println(s"$s:i=$i,f=$f")
Hello:i=5,f=2.1
scala> println(s"$ss:i=$i,f=$f")
<console>:17: error: not found: value ss
println(s"$ss:i=$i,f=$f")
^
scala> println(f"$s:i=$i,f=$f%.2f")
Hello:i=5,f=2.10
输出到文件
import java.io.PrintWriter
val outPutFile = new PrintWriter("D:\\大数据技\\Spark_scala\\scala\\data\\outData.txt")
outPutFile.println("outPut data!")
outPutFile.close()
读取文件
import scala.io.Source
val inPutFile = Source.fromFile("D:\\大数据技\\Spark_scala\\scala\\data\\readData.txt")
val textIter = inPutFile.getLines()
for(info <- textIter){
println(info)
}