使用gzip在scala中解压数据

decompress data in scala using gzip

当我尝试解压缩 gzip 文件时出现错误:

我的代码:

val file_inp = new FileInputStream("Textfile.txt.gzip")
val file_out = new FileOutputStream("Textfromgzip.txt")
val gzInp = new GZIPInputStream(new BufferedInputStream(file_inp))
while (gzInp.available != -1) {
  file_out.write(gzInp.read)
}
file_out.close()

输出:

scala:25: error: ambiguous reference to overloaded definition,
both method read in class GZIPInputStream of type (x: Array[Byte], x: Int, x: 
Int)Int
and  method read in class InflaterInputStream of type ()Int
match expected type ?
file_out.write(gzInp.read)
                     ^
one error found

如果有人知道这个错误请帮助我。

在 scala 中 gzip 压缩和解压缩的工作模型:

//create a text file and write something ..
val file_txt = new FileOutputStream("Textfile1.txt")
file_txt.write("hello this is a sample text ".getBytes)
file_txt.write(10) // 10 -> \n (or) next Line
file_txt.write("hello it is  second line".getBytes)
file_txt.write(10)
file_txt.write("the good day".getBytes)
file_txt.close()

// gzip file 

val file_ip = new FileInputStream("Textfile1.txt")
val file_gzOut = new GZIPOutputStream(new FileOutputStream("Textfile1.txt.gz"))
file_gzOut.write(file_ip.readAllBytes)
file_gzOut.close

//extract gzip

val gzFile = new GZIPInputStream(new FileInputStream("Textfile1.txt.gz"))
val txtFile = new FileOutputStream("Textfrom_gz.txt")
txtFile.write(gzFile.readAllBytes)
gzFile.close

不要忘记关闭导致“截断的 gzip 输入”的文件