Reputation: 712
I have A String object that I want to save to a file, and I dont care if it is saved as plain text or binary. I have tried saving as plain text and it was about 27 bytes. I then tried ObjectOutputStream
and it was 24 bytes. Is there any better way of saving String objects to a file? The string is 189:25:600:-324324214& and intend to have thousands of them. Thats why I want it compressed, and of course each String will be a bit different
Upvotes: 1
Views: 513
Reputation: 15418
Followings are some option to use for compressing:
Well i have only used 1,2,4 and 7 until now :). using XZ seems reasonable to me, fast and higher compression ration and very easy to use.
XZOutputStream out = new XZOutputStream(outstream, LZMA2Options);
InputStream in = new XZInputStream(anInputstream);
Upvotes: 2
Reputation: 234807
Wrap a FileOutputStream
inside a DeflatorOutputStream
inside an ObjectOutputStream
to create the file. (Write the entire array as a single object.) Then wrap a FileInputStream
inside an InflatorInputStream
inside an ObjectInputStream
to read.
Upvotes: 2