my requirement is to unzip a log file dynamically and write it in the console. But I am getting an exception
java.util.zip.ZipException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:166) ~[?:?]
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:80) ~[?:?]
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:92) ~[?:?]
here is my code
private static void readLogFile(File f) {
try(BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(f)), "UTF-8"))) {
String nextLine;
while ((nextLine = reader.readLine()) != null) {
System.out.println(nextLine);
}
} catch (FileNotFoundException e) {
logger.error("file doesn't exist." );
} catch (IOException e) {
logger.error("Error reading the file", e);
}
}
The size of my file is around 50 MB The size of my .gz file is 2.4 MB
I have already tried unzipping the file in the terminal and it works so the file is not corrupt as well
can someone help me with what is going wrong here?