|
-
June 20th, 2012, 04:40 AM
#1
Understanding encoding
Hi all,
Part of my code have to send an email written in Spanish or Catalan, depending of language selected. Both languages have accents and other non-ASCII (7bit) printable characters. That's why I use Unicode to try to avoid printing wrong characters. This is the body (in spanish):
Code:
String body = "Se ha recibido la respuesta a la solicitud de tasaci\u00F3n.\n" +
"Oficina: " + objDatosTasacion.getDatosOficina().getCentro() + "\n" +
"C\u00F3digo tasaci\u00F3n: " + codigoCompuesto + "\n" +
"Empresa: " + nombreTasadora + "\n" +
"Cliente: " + nombreCliente;
To send email, this does not works:
Code:
BodyPart texto = new MimeBodyPart();
texto.setText(new String(body.getBytes(),"UTF-8"));
Which generates:
Se ha recibido la respuesta a la solicitud de tasaci?.
Oficina: 2400
C?igo tasaci?: 2400-03-00014
Empresa: Tinsa
Cliente: Pepito Gcia.
However, next code works, and print unicode characters successfully:
Code:
BodyPart texto = new MimeBodyPart();
texto.setText(new String(body.getBytes()));
I just wonder to know why first method does not works if I'm using UTF-8, which is a representation of Unicode, and the second one works. I need to understand how to deal with such characters, because they make me crazy 
The OS is IBM-AIX and Java file is created using vi. I'm not sure the encoding used to create java file by vi. Compiler is IBM-JDK 1.5.0.
Thanks a lot in advance,
Albert.
Please, correct me. I'm just learning.... and sorry for my english :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|