Created
November 30, 2021 17:34
-
-
Save scalactic/07418e3a935d4faaeef805682466ab49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def withOpen(fileName: String, mode: String, encoding: String)(fp: Iterator[String] => Unit ): Unit = { | |
import scala.io.Source | |
val source = Source.fromFile(fileName) | |
val lines = source.getLines() | |
fp(lines) | |
source.close | |
} | |
withOpen("myfile.txt", "r", "utf-8") { lines => | |
lines.foreach(println) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment