how to deal with franch character in java inside string

while storing the french character the value is going to changed what to do

[82 byte] By [bibhuti_82a] at [2007-11-27 11:55:32]
# 1

shut the **** up, *******. Four threads with absolutely useless information and no replies of yours to suggestions given. What do you think you're doing here?

CeciNEstPasUnProgrammeura at 2007-7-29 19:02:31 > top of Java-index,Java Essentials,Java Programming...
# 2

I think this will help u

String src = "French text";

byte[] utf8SrcBytes = src.getBytes("UTF8");

String utf8SrcString = new String (src.getBytes("UTF8"), 0, utf8SrcBytes.length, "UTF8");

convert string in to bytearray and again byte array into string

AmitChalwade123456a at 2007-7-29 19:02:31 > top of Java-index,Java Essentials,Java Programming...
# 3

if u convert them in UTF8 and write it then u can properly see those characters

AmitChalwade123456a at 2007-7-29 19:02:31 > top of Java-index,Java Essentials,Java Programming...
# 4

> I think this will help u

Maybe not, because it's not even determined where the problem lies. Maybe the way the file is read is crappy, or the way it's handled in the program is, or the way it's sent to the DB is, or the way the DB stores it is, or the way he looks at the stored data is.

CeciNEstPasUnProgrammeura at 2007-7-29 19:02:31 > top of Java-index,Java Essentials,Java Programming...
# 5

Actually i was facing same problem two days back ,,

where letter in Greek , or Chinese look like only ? ? in my file where i was trying to write those character

Then i did UTF8 stuff

and it works

may be same case here also

AmitChalwade123456a at 2007-7-29 19:02:31 > top of Java-index,Java Essentials,Java Programming...
# 6

Maybe your file editor was set up to read UTF8 and your program worked correctly...

CeciNEstPasUnProgrammeura at 2007-7-29 19:02:31 > top of Java-index,Java Essentials,Java Programming...
# 7

even if fileditor is set to UTF8, if u write to file by using fileOutputStream it shows ,, it writes to file but not exact character it just writes some garbage so in that case before writting to file u have to convert them into UTF8 stream ..

AmitChalwade123456a at 2007-7-29 19:02:31 > top of Java-index,Java Essentials,Java Programming...
# 8

String utf8SrcString = new String (src.getBytes("UTF8"), 0, utf8SrcBytes.length, "UTF8");

This advice is worse than useless. All it does is convert the string to a byte array and back again; it doesn't even change anything. You're probably thinking of a trick some people use to retroactively change the encoding of Properties files from ISO-8859-1 to UTF-8, but that's a bad practice, too. If you want to write text to a file using the UTF-8 encoding, you use an OutputStreamWriter, like so: FileOutputStream fos = new FileOutputStream("out.txt");

OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");

To read UTF-8 text, use an InputStreamReader: FileInputStream fis = new FileInputStream("in.txt");

InputStreamReader isr = new InputStreamReader(fis, "UTF-8");

If the file has already been read with the wrong encoding, you have garbage. Using tricks involving getBytes() and new String() may seem to fix it, but the data is still corrupt, and eventually it will cause very hard-to-find bugs.

Message was edited by:

uncle_alice

Forgot to include the encoding for the InputStreamReader

uncle_alicea at 2007-7-29 19:02:31 > top of Java-index,Java Essentials,Java Programming...