首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用gzip解压缩scala中的数据

使用gzip解压缩scala中的数据
EN

Stack Overflow用户
提问于 2022-03-15 04:10:28
回答 1查看 246关注 0票数 0

当我试图解压缩gzip文件时,我得到了错误:

我的代码:

代码语言:javascript
运行
复制
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()

产出:

代码语言:javascript
运行
复制
scala:25: error: ambiguous reference to overloaded definition,
both method read in class GZIPInputStream of type (x$1: Array[Byte], x$2: Int, x$3: 
Int)Int
and  method read in class InflaterInputStream of type ()Int
match expected type ?
file_out.write(gzInp.read)
                     ^
one error found

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-15 08:28:22

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

代码语言:javascript
运行
复制
//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输入”的文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71476964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档