Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

writeUTF() for UTF-8 encoding

807607Sep 29 2006 — edited Oct 4 2006
Alright, here's what im trying to do.
Read chinese characters from an excel sheet, put it i a String variable, then write it to a .txt file. Here is what i have tried with no success:

//all the excel connect and other stuff up ehre

Try 1:
..
aword[.i.] = rs.getString(3);
...
Writer bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("mytxt.txt"),"UTF-8"));



bw.write("aword[.i.]");
bw.close();
...
Outputs: ??????? to the file ... should be some chinese characters

Try 2:
..
aword[.i.] = new String(rs.getString(3).getBytes("UTF-16LE"), "UTF-8");
...
Writer bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("mytxt.txt"),"UTF-8"));

bw.write("aword[.i.]");
bw.close();
...
Outputs: ??????? to the file ... should be some chinese characters


Try 3:
..
aword[.i.] = rs.getString(3);
...
DataOutputStream dos = new DataOutputStream(new FileOutputStream("mytxt.txt));

dos.writeUTF(aword[.i.]);
dos.close()
...
Outputs: ????? To the txt file

Try 4:
..
aword[.i.] = new String(rs.getString(3).getBytes("UTF-16LE"), "UTF-8");
...

DataOutputStream dos = new DataOutputStream(new FileOutputStream("mytxt.txt));

dos.writeUTF(aword[.i.]);
dos.close()
...
Outputs nothing to the text file.

For the sake of the program the string from the excel sheet must be stored an array.
Anyone have any ideas of what the problem is? I tried looking on all other related threads.
(periods in string array is to get rid of italics for the sake of this post)

Message was edited by:
rayhab
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 1 2006
Added on Sep 29 2006
5 comments
460 views