I chart history files stored as gz files.
Is there a way I can load a gz file in java
so far the nly results i got from google is to run external program to decompress it , I rather have it done within java.
Asked
Active
Viewed 1,870 times
-4

Ted pottel
- 6,869
- 21
- 75
- 134
-
Did you try searching for “java gzip”? – VGR Jul 18 '17 at 17:43
-
What do you mean by **load a gz file in java**? Is this of no help to you -> https://stackoverflow.com/questions/1080381/gzipinputstream-reading-line-by-line – Am_I_Helpful Jul 18 '17 at 17:44
1 Answers
0
You can try GZIPInputStream class. https://docs.oracle.com/javase/7/docs/api/java/util/zip/GZIPInputStream.html
There are two main methods in this class for closing stream and reading data.
void close() Closes this input stream and releases any system resources associated with the stream.
int read(byte[] buf, int off, int len) Reads uncompressed data into an array of bytes.
This guy asked similar question on Extract .gz files in java so you can try to use it as sample.
This is the sample:
public static void gunzipIt(String name){
byte[] buffer = new byte[1024];
try{
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream("/var/www/html/grepobot/API/"+ name + ".txt.gz"));
FileOutputStream out = new FileOutputStream("/var/www/html/grepobot/API/"+ name + ".txt");
int len;
while ((len = gzis.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
gzis.close();
out.close();
System.out.println("Extracted " + name);
} catch(IOException ex){
ex.printStackTrace();
}
}

Ivan Palijan
- 1
- 2
-
Can you add a short summary of the link you provided. Links are welcome on SO but they tend to rot. – litelite Jul 18 '17 at 17:52
-