bing
Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
×
UPTO
50%
OFF!
Intellipaat
Intellipaat
  • Live Instructor-led Classes
  • Expert Education
  • 24*7 Support
  • Flexible Schedule

Overview of reading and writing file oprations

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

 

Writing Data form 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()

}

}

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

 

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

}

}

}

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 Significance Of Scala!

Previous Next

Download Interview Questions asked by top MNCs in 2018?

"0 Responses on Scala File Input and Output"

    100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.
    top

    Sales Offer

    Sign Up or Login to view the Free Scala File Input and Output.