Read File Content in Scala

In this example, we will show you about how to read file content in scala program language. The example were tested with environment and attached in the post.

Example Code

import java.io.File;
import java.io.FileReader;
object ReadFile {
def main(args: Array[String]) {
var file = new File("abc.txt");
var fileReader = new FileReader(file);
var data = fileReader.read();
while(data != -1) {
print(data.toChar);
data = fileReader.read();
}
fileReader.close();
}
}

Input File

How to Read a File Content in Scala

Output

Hello everyone, This is Dinesh Krishnan

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *