开发者

How to store the file as an array in scala?

开发者 https://www.devze.com 2023-02-11 21:59 出处:网络
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 wr开发者_Python百科ote:

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 wr开发者_Python百科ote:

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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消