当前位置:网站首页>Scala IO read by line

Scala IO read by line

2022-06-25 01:03:00 Jue Niu thunder plough hot blade

import scala.io.Source

// Source Class extends from Iterator
object D01_ According to the line read  {
    

  def main(args: Array[String]): Unit = {
    
    //  Register target objects 
    val source = Source.fromFile("./data/1.txt", "utf-8")
    //  Read in line bit units 
    val lines: Iterator[String] = source.getLines()
    val list = lines.toList
    for (data <- list) println(data)
    //  Release resources 
    source.close()
  }

}

1.txt data

  		  The spring river and the moon 

【 author 】 Zhang Ruoxu 【 Dynasty 】

The spring tide is even with the sea , The moon and the tide rise in the sea .

With the waves of thousands of miles , Where is the spring river without the moon !

The river flows around Fangdian , All the flowers in the forest are like graupel ;

I don't feel the frost flying in the air , White sand can't see on Ting .

There is no fine dust in the river , The lone moon in the sky .

Who by the river saw the moon for the first time ? At the beginning of the year, Jiang Yue took photos of people ?

Life is endless , Jiang Yue looks similar every year .

I don't know who Jiang Yue is waiting for , But see the Yangtze River sending water .

White clouds go all the way , The green maple is full of sorrow .

Who's going to boat tonight ? Where is the lovesickness moon tower ?

Poor Yue Pei , You should take a picture of the dressing table .

I can't roll in the Yuhu curtain , Whisk the clothes and anvil .

At this time, we don't know each other , May the moon shine on you .

The long flying light of wild geese is not enough , Fish and Dragons dive into the water .

Last night I dreamed of falling flowers , Poor spring will not return home .

The river flows away in spring , The moon falls on the river and the lake slopes to the West .

The slanting moon sinks into the sea mist , Jieshi Xiaoxiang infinite road .

I don't know how many people will come back in the month , The falling moon shakes all the trees in the river .

1.txt Location
1.txt

原网站

版权声明
本文为[Jue Niu thunder plough hot blade]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210544013758.html