Serialize a HashMap into text?

Hi experts,

I need to store a HashMap as a bunch of bytes, and I could use serialization. But my keys and values are all strings, and in my system text processing is much faster. How could I encode it all into text? I stared by using newline as separator, but then I got into values that have newlines, and it all broke.

Thank you
LVL 1
kerznerAsked:
Who is Participating?
 
Gibu GeorgeConnect With a Mentor Chief Technology OfficerCommented:
If the keys and values are text use properties instead of hashmap, there are methods load() and store(0 methods which allows you to write to a property file and read from there
0
 
ksivananthConnect With a Mentor Commented:
you can wrap the key and value string into single/double quote and escape the quote if it occurs with in the string.
0
 
kerznerAuthor Commented:
Let me try...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Gibu GeorgeChief Technology OfficerCommented:
If you are using Java 1.5 then there is option to storeToXMl and loadFromXML also
0
 
kerznerAuthor Commented:
Let me try that too - that would be more automatic
0
 
SteinerCommented:
You can also have look at XStream for serialization to XML, even with Java 1.4.
0
 
kerznerAuthor Commented:
load() and store() worked, and if I need text-only later on, I'll use the quote escape
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.