Download Scala Tutorial (PDF Version) - Tutorials Point
Download Scala Tutorial (PDF Version) - Tutorials Point
Download Scala Tutorial (PDF Version) - Tutorials Point
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