LoginSignup
2
1

More than 5 years have passed since last update.

Scalaでファイルの内容を1行にまとめる

Last updated at Posted at 2016-01-08

複数行に分かれている内容をカンマ区切りで1行にまとめる。

import scala.io.Source

object read {
  def main(args: Array[String]):Unit = {
    val filename= args(0)
    val s = Source.fromFile(filename)
    try {
      println(s.getLines.toList.mkString(","))
    } finally {
      s.close
    }
  }
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1