Reputation: 711
I am completely new to spark and scala.
I want to read a file into an array list.
This is how its done in java.
List<String> sourceRecords;
sourceRecords = new ArrayList<String>();
BufferedReader SW;
SW = new BufferedReader(new FileReader(srcpath[0].toString()));
String srcline ;
while ((srcline = SW.readLine()) != null) {
sourceRecords.add(srcline.toString());
}
How to do it in scala in spark
Upvotes: 2
Views: 10194
Reputation: 20816
It's very easy. For example,
val rdd = sc.textFile("your_file_path")
val sourceRecords = rdd.toArray
However, you don't need to convert rdd
to Array
. You can manipulate rdd
like an Array
.
You can find more information in https://spark.incubator.apache.org/examples.html
Upvotes: 5