Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left
Apply NowLogin using Social Account
     Continue with GoogleLogin using your credentials
Scala uses scala.io.Source
class to read the files from the operating system. Here is one example code on how you can read each line from a file named new.txt
:
import scala.io.Source;
for (line <-Source.fromFile("new.txt").getLines) {
println(line)
}
A complete file path can also be specified instead of a standalone file name.
number_of_lines
mbox-short.txt
which is located at /cxldata/datasets/project/mbox-short.txt
and read it to get each line using getLines
functionNote: If your logic is correct then your function should return 1910.
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...