Basic I/O Operations and using Scala Collections APIs

As part of this topic, we will explore Basic I/O operations

  • Read data from files
  • Convert into collection
  • Perform collection operation to preview the data
  • Run map-reduce operations

Reading data from files

  • To read files from a file system in scala there is a package called scala.io
  • In scala.io we have a package named Source which is used to read files from the file system
  • Important operations in Source package are as follows

Few APIs from Source to read data

  • fromFile is used to read data from a file
  • fromIterable is used to read data from collection
  • fromURI creates Source from a file with given file: URI
  • fromURL is used to read data from HTTP URL

Example

https://gist.github.com/dgadiraju/bc8dfabf75a20e92cfd85384aa923811

Share this post