Skip to content

Instantly share code, notes, and snippets.

@pauca
Last active April 30, 2022 06:14
Show Gist options
  • Save pauca/caad0621715e28e0457f to your computer and use it in GitHub Desktop.
Save pauca/caad0621715e28e0457f to your computer and use it in GitHub Desktop.
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