09.10.2014 Views

Download Scala Tutorial (PDF Version) - Tutorials Point

Download Scala Tutorial (PDF Version) - Tutorials Point

Download Scala Tutorial (PDF Version) - Tutorials Point

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C:/>scala Test<br />

scala Test<br />

Please enter your input : <strong>Scala</strong> is great<br />

Thanks, you just typed: <strong>Scala</strong> is great<br />

C:/><br />

Reading File Content:<br />

Reading from files is really simple. You can use <strong>Scala</strong>'s Source class and its companion object to read files.<br />

Following is the example which shows you how to read from "test.txt" file which we created earlier:<br />

import scala.io.Source<br />

object Test {<br />

def main(args: Array[String]) {<br />

println("Following is the content read:" )<br />

}<br />

}<br />

Source.fromFile("test.txt" ).foreach{<br />

print<br />

}<br />

When the above code is compiled and executed, it will read test.txt file and display the content on the screen:<br />

C:/>scalac Test.scala<br />

C:/>scala Test<br />

scala Test<br />

Following is the content read:<br />

Hello <strong>Scala</strong><br />

C:/><br />

TUTORIALS POINT<br />

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!