import java.io.{File, PrintWriter}

import scala.io.Source
object Test {
  def main(args: Array[String]): Unit = {
    val filename = "src//a.txt"//读取的文件
    val write = new PrintWriter(new File("src//b.txt"))//写入的文件
    Source.fromFile(filename).getLines() //获取文本所有的内容,返回一个迭代器
    //遍历文本内容
    for(line<- Source.fromFile(filename).getLines()){
      println(line)//打印文本内容
      write.println(line) //写入到文件
    }
  }
}

 读取文件需要导入scala.io.Source,写入文件使用的是java的PrintWriter。

相关文章:

  • 2022-12-23
  • 2023-04-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
  • 2021-06-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-10
  • 2021-09-03
  • 2021-05-19
  • 2021-08-26
相关资源
相似解决方案