我在阅读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);
}