核心内容: 1、scala中文件的读取、写入操作代码实战 2、控制台操作代码实战
1、scala中文件的读取、写入操作代码实战
1>Scala中常用scala.Source类来完成文件的读取 2>Java中的IO操作在scala中同样适用 示例代码1:利用scala.Source类来完成文件的读取操作
package IT04
import scala.io.Source
object App
{
def main(args:Array[String]):Unit=
{
val fr = Source.fromFile(
"C:\\word.txt")
for(line<- fr.getLines()) println(line)
fr.close
}
}
运行结果:
hello she
hello he
hello
me
hello she
示例代码2:利用Java中的PrintWriter
转载请注明原文地址: https://ju.6miu.com/read-1303862.html