|
Author |
Topic: save in compressed .gz format (Read 320 times) |
|
marcello
|
save in compressed .gz format
« on: Jul 25th, 2004, 10:36am » |
|
Is it possible to save text files in .gz compressed format using p5? Marcello
|
« Last Edit: Jul 25th, 2004, 11:05am by marcello » |
|
|
|
|
fry
|
Re: save in compressed .gz format
« Reply #2 on: Jul 25th, 2004, 6:04pm » |
|
gzip is in java 1.1 as well, so something like this should work: (untested..) Code:try { public void saveStrings(String filename, String strings[]) { FileOutputStream fos = new FileOutputStream(filename); GZIPOutputStream output = new GZIPOutputStream(fos); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output)); for (int i = 0; i < strings.length; i++) { writer.println(strings[i]); } writer.flush(); } } catch (Exception e) { e.printStackTrace(); } |
|
|
|
|
|
marcello
|
Re: save in compressed .gz format
« Reply #3 on: Jul 25th, 2004, 6:23pm » |
|
narain and fry, Thank you very much for your inputs. I'll tell you here if I'll be able to get a good return on your suggestions. narain, Together with a bunch of friends I'm working to an application that should allow users to store txt files on a server. These txt files contain the code of 3d virtual creatures in the style of sodaplay (look at my homepage). Now the problem is that those data could take a lot of space so the best thing is to save these files in compressed format. Best Regards, Marcello
|
|
|
|
marcello
|
Re: save in compressed .gz format
« Reply #4 on: Jul 25th, 2004, 8:24pm » |
|
Ok! With just few modifies i was able to make work the fry's code. Here is the tested code: Code:String [] file; void setup() { file = new String [100]; for (int i=0; i<100; i++) { file[i]="thank you very mutch guys ;)"; } saveStrings("thanks.txt.gz",file); } public void saveStrings(String filename, String strings[]) { try { FileOutputStream fos = new FileOutputStream(filename); GZIPOutputStream output = new GZIPOutputStream(fos); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output)); for (int i = 0; i < strings.length; i++) { writer.println(strings[i]); } writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } |
| Thank you very much again, Marcello
|
« Last Edit: Jul 25th, 2004, 8:28pm by marcello » |
|
|
|
|
|