challenge 条件を満たす行を取り除く

ファイルから1行ずつ読み込み、"#"で始まる行だけを取り除いてファイルに出力するコードを書いてください。

サンプル入力

hello!
# remove this
 # don't remove this
bye!
サンプル出力
hello!
 # don't remove this
bye!

Posted feedbacks - Scala


	
1
2
3
4
5
import scala.io.Source
import java.io._
val i = new BufferedWriter(new FileWriter(args(1)))
i.write(Source.fromFile(args(0)).getLines.filter(!_.startsWith("#")).mkString(""))
i.close

Index

Feed

Other

Link

Pathtraq

loading...