本文介绍了从FileChannel(Java NIO)读取GZIP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在给定FileChannel的情况下读取/解压缩.gz文件。

I need to read/unpack a .gz file given a FileChannel.

我使用GZIPInputStream解压缩GZIP档案,但这不会占用FileChannel。我没有访问FileChannel的原始FileInputStream。

I've played around with extracting GZIP archives using GZIPInputStream, but this won't take a FileChannel. I don't have access to the original FileInputStream that the FileChannel was taken from.

如果有人能告诉我一个好方法(或至少任何

If someone could tell me a good way (or at least any way) of reading GZIP from a FileChannel, I would greatly appreciate it.

改编自。

Adapted from a question on the Oracle forums.

推荐答案

您可以在FileChannel周围获取包装InputStream:

You could obtain a wrapping InputStream around the FileChannel:

FileChannel fc = ...
GZIPInputStream gis = new GZIPInputStream(Channels.newInputStream(fc));

在Java SE中。

Channels is in Java SE.

这篇关于从FileChannel(Java NIO)读取GZIP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 15:55