0
点赞
收藏
分享

微信扫一扫

scala对文件的读写操作

40dba2f2a596 2022-02-11 阅读 147
import java.io.{File, PrintWriter}

import scala.io.Source

object TestReadFile {
  def main(args: Array[String]): Unit = {
    //1.从文件中读取数据
    Source.fromFile("src/main/resources/test.txt").foreach(print)

    //2。将数据写入文件java中的
    val writer = new PrintWriter(new File("src/main/resources/test.txt"))
    writer.write("hello scala")
    writer.close()
  }
}

举报

相关推荐

0 条评论