• Articles
  • Tutorials
  • Interview Questions

Scala File Input and Output

Overview of reading and writing file operations

File operations mostly include reading data from the file or writing data into files.

Writing Data from File
e.g.

import java.io._
object Intellipaat {
def main(args: Array[String]) {
val writer = new PrintWriter(new File("intellipaat.txt" ))
writer.write("Hello Intellipaat")
writer.close()
}
}

Interested in learning Scala? Click here to learn more in this Scala Training in New York!

When we compile and execute this program then it writes Hello Intellipaat in intellipaat.txt file.

Certification in Bigdata Analytics

Reading Data from File
e.g.

import scala.io.Source
object Intellipaat {
def main(args: Array[String]) {
println("Data in File is:" )
Source.fromFile("intellipaat.txt" ).foreach{
print
}
}
}

Enroll yourself in Online Scala Training and give a head-start to your career in Apache Spark and Scala!

Compile and execute the above program:
scalac Intellipaat.scala
scala Intellipaat
Output
Data in file is: Hello Intellipaat

This blog will help you get a better understanding of the Significance Of Scala!

Course Schedule

Name Date Details
Big Data Course 16 Nov 2024(Sat-Sun) Weekend Batch View Details
23 Nov 2024(Sat-Sun) Weekend Batch
30 Nov 2024(Sat-Sun) Weekend Batch

About the Author

Technical Research Analyst - Data Engineering

Abhijit is a Technical Research Analyst specializing in Deep Learning. He holds a degree in Computer Science with a focus on Data Science. Being proficient in Python, Scala, C++, Dart, and R, he is passionate about new-age technologies. Abhijit crafts insightful analyses and impactful content, bridging the gap between cutting-edge research and practical applications.