Writing an ArrayList object to a File with encoding

E

Eren Aykin

Hi, I want to serialize and write an arraylist to a file, but the
problem is the strings in the arraylist needs to be encoded in
"windows-1254".
My current code is like:

FileOutputStream fout2= new FileOutputStream("C:\\vocabulary.txt");
ObjectOutputStream out2= new ObjectOutputStream(fout2);
out2.writeObject(vocArray); // vocArray is an arraylist

The words in the vocArray have some foreign language characters and
I've problem writing them to a file.
I know that OutputStreamWriter allows us to define encoding type so I
can write:
OutputStreamWriter osw2 = new OutputStreamWriter(out2,"windows-1254");

But I don't know how to write the arraylist object with a specific
encoding type.

Could anybody help me with this problem?
 
L

Lasse Reichstein Nielsen

Eren Aykin said:
Hi, I want to serialize and write an arraylist to a file, but the
problem is the strings in the arraylist needs to be encoded in
"windows-1254".

Uhm, why?
Either you serialize the ArrayList, and then you can't expect anything
of the output except that it can be deserialized again, or you
write the content of the ArrayList in a format of your choice.

.....
The words in the vocArray have some foreign language characters and
I've problem writing them to a file.

Serialization of strings should not have a problem at all. What
problems do you have?

/L
 
E

Eren Aykin

Oh! I'm sorry Lasse, as you said I really don't have a problem with
serialization. I just clicked on the serialized vocabulary.txt and saw
those awkward chars and thought that there must be a problem with
encoding.
I wish there was a way to delete my question, I think I need some fresh
air...
Thank you anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top