这个问题在这里已经有答案了:
hadoop:在hdfs中压缩文件(7个答案)
6年前关门了。
我是hdfs/hadoop新手,需要知道如何压缩hdfs目录中的文件hdfs://sandbox:8020/部分/路径。
我试过了
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();
但它不起作用。
有什么建议吗?提前谢谢。
1条答案
按热度按时间lfapxunr1#
下面的代码来自汤姆·怀特的权威指南。