Sha*_*baz 2 java compression gzip
我有一些数据在未压缩的文件中占用超过50MB,但压缩到不到半个MB使用gzip.
其中大部分是数字数据.我试图弄清楚如何处理这些数据而不必完全解压缩.例如,如果这个数据包含几个字符串和每个记录5个左右的数值,有没有办法可以解压缩一行(或一小组行),处理它们,然后丢弃它们?
UNIX提供实用程序,如zcat,grep等,直接对压缩数据进行操作,我想这样做在Java中.
谢谢
只需将您包裹FileInputStream在GZipInputStream:
public static BufferedReader createReader (File f, String encoding) throws IOException
{
try
{
InputStream in = new FileInputStream (f);
if (f.getName ().endsWith (".gz"))
in = new GZIPInputStream (in, 10240);
return new BufferedReader (new InputStreamReader (in, encoding));
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException("Missing encoding "+encoding, e);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
586 次 |
| 最近记录: |