Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

read unicode from file

Thread view: 
gert - 17 Aug 2006 11:09 GMT
I want to read a unicode String from a file:
           FileInputStream stream = new FileInputStream(file);

           DataInputStream din = new DataInputStream(stream);
           byte[] y = new byte[6];
           din.read(y);
           String unit = new String(y, "UTF-8");
           din.close();

If the file contains the entry \u00B0 I would expect if displaying unit
on a JLabel see the 'degree' sign (°).
But I see this: \u00B0
If I do the following: String unit = "\u00B0" an display this unit on a
JLabel it displays the '°' correctly.
What do I do wrong??
Many thanks for any help
Thomas Kellerer - 17 Aug 2006 11:28 GMT
> I want to read a unicode String from a file:
>             FileInputStream stream = new FileInputStream(file);
[quoted text clipped - 10 lines]
> If I do the following: String unit = "\u00B0" an display this unit on a
> JLabel it displays the '°' correctly.

> What do I do wrong??

Read the stuff using a Reader do not use a plain InputStream

Reader r = new InputStreamReader(new FileInputStream(file), "UTF-8"));

Thomas

Signature

It's not a RootKit - it's a Sony

Simon - 17 Aug 2006 12:15 GMT
Thomas Kellerer schrieb:
>> I want to read a unicode String from a file:
>>             FileInputStream stream = new FileInputStream(file);
[quoted text clipped - 16 lines]
>
> Reader r = new InputStreamReader(new FileInputStream(file), "UTF-8"));

Apart from that I understand that the file contains a literal backslash, a "u"
and four digits (as opposed to the file containing the byte sequence that is
represented by "00B0" in hex). Otherwise an InputStream would still not produce
the described output. If this is true, using a Reader will not help.

In that case you can refer to the following article, where it was discussed how
you can parse strings of your type:

news://News.CIS.DFN.de:119/1154597886.093932.227050@75g2000cwc.googlegroups.com

Cheers,
Simon


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.