Skip to content

Instantly share code, notes, and snippets.

@pauca pauca/gz.scala
Last active Jul 25, 2019

Embed
What would you like to do?
scala read / write from compressed gz
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
You can’t perform that action at this time.