File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes File with euro char Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "File with euro char" Watch "File with euro char" New topic
Author

File with euro char

Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 290

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...


-Chiru
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14428
    
  23

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 290

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42910
    
  68
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

Joined: Feb 18, 2008
Posts: 290

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
Marshal

Joined: Mar 22, 2005
Posts: 42910
    
  68
This should do the trick:

[ May 28, 2008: Message edited by: Ulf Dittmer ]
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 290

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
Marshal

Joined: Mar 22, 2005
Posts: 42910
    
  68
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

Joined: Feb 18, 2008
Posts: 290

ya it is solved i am useing "ISO-8859-1" while writeing
Thank you very much
Thanks..
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
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


Author of <a href="http://www.newsinjector.com" target="_blank" rel="nofollow">NewsInjector</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File with euro char