Domanda

I am trying to make a code that reads the lines in file and then store it as an array in scala?

The following is the code I wrote:

import scala.io.Source
val fname = args(0)
for (line <- Source.fromFile(fname).getLines)

I don't know what to do next?

Thank you in advance.

È stato utile?

Soluzione

If you want an array, you simply can call toArray on the getLines method.

val arrayOfLines = Source.fromFile(fname).getLines.toArray

(or .toList for an immutable list)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top