Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File with euro char

 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
i have a problem while creatting a file.
the file is .bin file which should have the byte 0x80 the decimal value is 128 the char is E euro symbol
i have a Integer value which is 128 i read from serial port while writting i am giving
write(128);
but the char which is taking is '?' and hex value is 3f and the Dec value is 63.

please help me i am watting for the replay...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us some code that produces the wrong result? That might make it easier to help you.

Where do you see it displayed as a '?' (question mark)?

Note that you have to take the character encoding into account. The code 128 is the Euro sign in Windows codepage 1252, but not in most other standard character encodings such as UTF-8 or ISO-8859-1. If the software you are using to display the character doesn't use cp-1252, then you will not see an Euro sign if you send it character code 128.
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you really don't specify the character encoding. For all files that contain anything but US-ASCII you should always specify the encoding. Plus, in Java it's customary to use Unicode, so you should write the "\\u20AC" character, in which case Java will write whatever is appropriate for the given encoding.

If you need files that can be used cross-platforms, these days it's best to use the UTF-8 encoding; just remember to specify that both for reading and for writing.
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you help how can i write with that UTF-8 while writting

or

tell me how can i get the unicode like \u20ac from int value or char value
[ May 28, 2008: Message edited by: Chiru Raj ]
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should do the trick:

[ May 28, 2008: Message edited by: Ulf Dittmer ]
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i have a problem
for writting to a file

the file is open as you told
here i am calling

i am using the editer called HHD's HEX Editor which is dispalying
c2 80 for 0x80
c3 bf for 0xff
why?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not write integer values to a Unicode file. 80 is a control character, while FF is "LATIN SMALL LETTER Y WITH DIAERESIS". Are those really the characters you want to have in the file?

What are you really trying to do?

Also note that the resulting UTF-8 file is a text file, not a binary file. Looking at it in a hex editor isn't as simple as looking at an ASCII file.
[ May 28, 2008: Message edited by: Ulf Dittmer ]
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya it is solved i am useing "ISO-8859-1" while writeing
Thank you very much
Thanks..
 
Vilmantas Baranauskas
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You MUST read this article before going any further.

"The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" by Joel Spolsky:
http://www.joelonsoftware.com/articles/Unicode.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic