Quantcast
Viewing latest article 2
Browse Latest Browse All 20

Answer by Li Haoyi for Read entire file in Scala?

If you don't mind a third-party dependency, you should consider using my OS-Lib library. This makes reading/writing files and working with the filesystem very convenient:

// Make sure working directory exists and is emptyval wd = os.pwd/"out"/"splash"os.remove.all(wd)os.makeDir.all(wd)// Read/write filesos.write(wd/"file.txt", "hello")os.read(wd/"file.txt") ==> "hello"// Perform filesystem operationsos.copy(wd/"file.txt", wd/"copied.txt")os.list(wd) ==> Seq(wd/"copied.txt", wd/"file.txt")

with one-line helpers for reading bytes, reading chunks, reading lines, and many other useful/common operations


Viewing latest article 2
Browse Latest Browse All 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>