I’m java beginner, I need something like this:
String2GzipFile (String file_content, String file_name)
String2GzipFile("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "lorem.txt.gz")
I cant figure out how to do that.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are two orthogonal concepts here:
OutputStreamWriterGZIPOutputStreamSo in the end you’ll want to:
OutputStreamwhich writes to wherever you want the result (e.g. a file or in memory via aByteArrayOutputStreamOutputStreamin aGZIPOutputStreamGZIPOutputStreamin anOutputStreamWriterusing an appropriate charset (e.g. UTF-8)OutputStreamWriterFor example:
Note that I’m closing
outputeven if we fail to create the writer, but we still need to closewriterif everything is successful, in order to flush everything and finish writing the data.