Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading lines from file in Scala

Tags:

io

scala

Again Scala basic operations are making my life painful :D. So I have to read lines from file...just a trivial I/O operation.

In every example on internet they are doing:

import scala.io.Source

for(line <- Source.fromPath("integerArray.txt").getLines())
      println(line)

But my IntelliJ is throwing error : value fromPath is not a member of object scala.io.Source.

Does anyone knows what is problem here? ... I have installed last version of Scala few months ago and IntelliJ Scala plugin is also up to date so I doubt this might be a reason...

like image 320
Ivan Longin Avatar asked Jul 14 '13 10:07

Ivan Longin


2 Answers

There is no fromPath in Source, just a fromFile, which accepts a String path. Good luck on Coursera.

like image 96
Didier Dupont Avatar answered Nov 15 '22 18:11

Didier Dupont


There was Source.fromPath around 2.8. Briefly.

What, you're not using this version?

It was removed here, with "Review by community."

See? We just weren't paying attention.

like image 35
som-snytt Avatar answered Nov 15 '22 19:11

som-snytt