Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Scala, when reading from a file how would I skip the first line?

Tags:

scala

The file is very large so I cannot store in memory. I iterate line by line as follows

for (line <- Source.fromFile(file).getLines) {
}

How can I specify that the first line should be skipped?

like image 453
deltanovember Avatar asked Aug 06 '11 21:08

deltanovember


1 Answers

How about:

for (line <- Source.fromFile(file).getLines.drop(1)) {
  // ...
}

drop will simply advance the iterator (returned by getLines) past the specified number of elements.

like image 110
Ben James Avatar answered Oct 19 '22 21:10

Ben James