我有一个.gz格式的文件。读取此文件的Java类是GZIPInputStream。但是,此类不会扩展Java的BufferedReader类。结果,我无法逐行读取文件。我需要这样的东西
reader = new MyGZInputStream( some constructor of GZInputStream)
reader.readLine()...
我虽然创建了扩展java的Reader或BufferedReader类并使用GZIPInputStream作为其变量之一的类。
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.util.zip.GZIPInputStream;
public class MyGZFilReader extends Reader {
private GZIPInputStream gzipInputStream = null;
char[] buf = new char[1024];
@Override
public void close() throws IOException {
gzipInputStream.close();
}
public MyGZFilReader(String filename)
throws FileNotFoundException, IOException {
gzipInputStream = new GZIPInputStream(new FileInputStream(filename));
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
// TODO Auto-generated method stub
return gzipInputStream.read((byte[])buf, off, len);
}
}
但是,这在我使用时不起作用
BufferedReader in = new BufferedReader(
new MyGZFilReader("F:/gawiki-20090614-stub-meta-history.xml.gz"));
System.out.println(in.readLine());
有人可以建议如何进行..