In addition to reading data from the console, Scala also supports reading data from files. It is possible to read data from a file in Scala using the Scala.io.Source class.
- [Instructor] It's not only possible to read data…from the console, we can also read data…from a file in Scala.…We do this using the Scala.io.source class.…In your chapter 03 03 02,…you should have a template file called readFromFiles.scala.…If you open it up, it'll look like this.…Let's start by adding the import statement…so we can use this new library.…So I'm going to do import io.Source._…where underscore, remember, is a wild card…so that will give me all the methods…that exist in the io.Source class.…
Alright, let's add some code to our application.…To read individual lines and process them one at a time,…we can use a for loop.…Let's start by creating a file.…So I wanted to show you how to do that.…There's also a file in your exercise files folder…called poem.txt that we'll take a look at,…but let's create a new file…that holds the colors of the rainbow.…So we're going to go to File, New,…and we'll come down to File.…And let's just call it rainbow.txt.…So it's going to be a text file.…
In here, let's add the colors.…
Join Peggy Fisher as she helps get you started with Scala, so you can leverage the unique capabilities it offers. First, learn the basics of type inference, variables, loops, functions, and operators. Then, find out how to read files using a console, perform pattern matching, handle exceptions, and more. Finally, learn how to use classes, fields, methods, and objects.
- Integrating with IDEs
- Scala worksheets
- Scala repl sessions
- Type inference
- Creating variables
- Working with loops
- Higher-order functions
- Scala operators
- Working with decision statements
- Handling exceptions using try or catch
- Working with tuples and arrays
- Classes, fields, and methods
Skill Level Intermediate
Java Platforms Compared: SE vs EE vs MEwith Peggy Fisher25m 38s Intermediate
1. Getting Started with Scala
2. Scala Basics
3. More Scala Basics
4. Objects with Scala
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.