Last active
April 30, 2022 06:14
-
-
Save pauca/caad0621715e28e0457f to your computer and use it in GitHub Desktop.
scala read / write from compressed gz
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
import java.io._ | |
import java.util.zip._ | |
import scala.io.Source | |
var in = new GZIPInputStream(new FileInputStream("test.gz")) | |
// write setup in different objects to close later properly (important for big files ) | |
var fos = new FileOutputStream("test2.gz") | |
var gzos = new GZIPOutputStream( fos ) | |
var w = new PrintWriter(gzos) | |
for (line <- Source.fromInputStream(in).getLines()) { | |
println(line) | |
w.write(line+"\n") | |
} | |
w.close() | |
gzos.close() | |
fos.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment