我在阅读 GZipped BlueCoat 日志文件时遇到问题。该文件的前六行是一个标题,这些行可以完美读取,但没有以下内容。
我已经尝试手动解压缩日志,然后尝试使用稍微修改的代码读取文件,并且效果很好。我怀疑这是 ASCII 与 UTF8 与 UTF16 的问题,但我无法深入了解这一点,特别是因为它似乎改变了中间文件。
我目前的代码是:
InputStream fileStream;
InputStream gzipStream;
Reader decoder;
BufferedReader thisBr;
try {
fileStream = new FileInputStream(currentFile);
gzipStream = new GZIPInputStream(fileStream);
decoder = new InputStreamReader(gzipStream, "UTF-8");
thisBr = new BufferedReader(decoder);
String logLine = thisBr.readLine();
while (logLine != null)
{
logWriter.write(logLine + "\n");
logLine = thisBr.readLine();
}
logWriter.flush();
gzipStream.close();
} catch (IOException e) {
System.out.println("Exception has been thrown:" + e);
}