gpt4 book ai didi

java - 如何在 hdfs 上使用 java 压缩文件

转载 作者:可可西里 更新时间:2023-11-01 14:54:01 27 4
gpt4 key购买 nike

<分区>

我是 hdfs/hadoop 的新手,需要知道如何压缩 hdfs 目录中的文件,例如hdfs://sandbox:8020/some/path.

我试过了

      Path p = new Path("/my/path/test1.gz");
FSDataOutputStream os = fs.create(p);

GZIPOutputStream gzipOs = new GZIPOutputStream(new BufferedOutputStream(os));

Path filePath = file.getPath();
FSDataInputStream is = fs.open(filePath);

System.out.println("Writing gzip");

byte[] buffer = new byte[1024];
int len;
while((len= is.read(buffer)) != -1){
gzipOs.write(buffer, 0, len);
}
//close resources
is.close();
gzipOs.close();

但它不起作用。

有什么建议吗?提前致谢。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com