So I basically have the following code to read a .csv file and store it in an `Array[Array[String]]`:

```
def load(filepath: String): Array[Array[String]] = {
      var data = Array[Array[String]]()
      val bufferedSource = io.Source.fromFile(filepath)
      for (line <- bufferedSource.getLines) {
        data :+ line.split(",").map(_.trim)
      }
      bufferedSource.close
      return data.slice(1,data.length-1) //skip header
  }

```

Which works for files that are not stored on HDFS. However, when I try the same thing on HDFS I get 

> 
> No such file or directory found
> 
> 
> 

When writing to a file on HDFS I also had to change my original code and added some `FileSystem` and `Path` arguments to `PrintWriter`, but this time I have no idea at all how to do it.

I am this far:

```
  def load(filepath: String, sc: SparkContext): Array[Array[String]] = {
      var data = Array[Array[String]]()
      val fs = FileSystem.get(sc.hadoopConfiguration)
      val stream = fs.open(new Path(filepath))
      var line = ""
      while ((line = stream.readLine()) != null) {
        data :+ line.split(",").map(_.trim)
      }

      return data.slice(1,data.length-1) //skip header
  }

```

This should work, but I get a `NullPointerException` when comparing line to null or if its length is over 0.