This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes compressing a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compressing a string" Watch "compressing a string" New topic
Author

compressing a string

dale con
Ranch Hand

Joined: Apr 15, 2005
Posts: 93
hi all

i'm hving some trouble with compressing (zipping) a String, i'm not too sure how to do t. i've seend examples of compressing a file but not a string, can anyone help me out

I'm trying to modeify this so it takes a string and not a file but getting no where, i know i have to use ByteArrayInputStream but don't know how to use in the example i have


String inFilename = "c:\articles\examplegzip.gz";
GZIPInputStream gzipInputStream =
new GZIPInputStream(new FileInputStream(inFilename));
// Open the output file
String outFilename = "c:\articles\statebirdsclone.txt";
OutputStream out = new FileOutputStream(outFilename);

// Transfer bytes from the compressed file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = gzipInputStream.read(buf)) > 0) {
out.write(buf, 0, len);
}

// Close the file and stream
gzipInputStream.close();
out.close();
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
You can try with StringReader/ StringWriter


ASCII silly question, Get a silly ANSI.
 
Consider Paul's rocket mass heater.
 
subject: compressing a string
 
Similar Threads
Corrupt GZIP trailer
Unzipping a .zip file containing .gif files
problems with unziping image files
ZipOutputStream
Install java files