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 / October 2006

Tip: Looking for answers? Try searching our database.

Euro sign not displayed when transmitted through stream

Thread view: 
Raga - 09 Oct 2006 15:21 GMT
Hi,

This is what is being done. Euro sign is initialized as a String & then
written through PrintWriter into a custom stream, where it's converted
to type int[]. When this is read in the client end & displayed, it is
getting displayed as a '?'. In short, this is how it is coded:

String string = new String("€");
PrintWriter writer = new PrintWriter(new customOutputStream(), true);
writer.print(string);

In the custom stream, the write() method is defined like this:

public void write(int arg0) throws IOException
{
     data[top][j++] = arg0;
}

where data[][] is an 'int' array.

For the string "€", if I print the value of data[][], am getting some
numbers. How do I verify if the numbers that I get corresponding to the
String "€" is correct?

In the client, a method gets data[][] & writes to the screen. Am
getting '?'. If I set the OutputStream's encoding as UTF-8, am getting
3 '?'s. For UTF-16. am getting 2 '?'s. Can someone please throw some
light on this?

Thanks.
KiLVaiDeN - 09 Oct 2006 15:39 GMT
> Raga wrote:
>
[quoted text clipped - 28 lines]
>
> Thanks.

Hello,
Have you tried using an OutputStreamWriter ?

Cheers,
K
Lothar Kimmeringer - 09 Oct 2006 15:40 GMT
> In the client, a method gets data[][] & writes to the screen. Am
> getting '?'. If I set the OutputStream's encoding as UTF-8, am getting
> 3 '?'s. For UTF-16. am getting 2 '?'s. Can someone please throw some
> light on this?

What's the encoding of the screen (aka console)? It doesn't seem
to be UTF-8 or UTF-16. Is it a windows-system? Then it's AFAIR
cp1252. So you should try something like

out = OutputStreamWriter(System.out, System.getProperty("file.encoding"));
out.write("€\n");

If you still get '?' your system-encoding is ASCII or Latin1 or
another encoding that doesn't know the euro-sign.

Regards, Lothar
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!

Raga - 09 Oct 2006 15:58 GMT
Hi,

Thanks to all for your replies.

1. How do I change my system's default encoding?

2. Another method I tried is to instantiate PrintWriter like this:

OutputStreamWriter outWriter = new OutputStreamWriter(new
DataSEPipedOutputStream(), "UTF-8");
PrinWriter writer = new PrintWriter(outWriter, true);

But this gives '???' on the screen.

If I change that to UTF-16, instead of UTF-8, I get '??' on the screen.

Not sure why this weird behaviour.

Thanks.

> > In the client, a method gets data[][] & writes to the screen. Am
> > getting '?'. If I set the OutputStream's encoding as UTF-8, am getting
[quoted text clipped - 18 lines]
> Always remember: The answer is forty-two, there can only be wrong
>                  questions!
Lothar Kimmeringer - 09 Oct 2006 16:04 GMT
> 1. How do I change my system's default encoding?

Depends on the system.

> 2. Another method I tried is to instantiate PrintWriter like this:
>
[quoted text clipped - 3 lines]
>
> But this gives '???' on the screen.

If your console expects e.g. Latin-15, you simply don't fit
it the way being expected. You must use the encoding of the
console. It's not OK to just set the encoding in the way you
like.

> If I change that to UTF-16, instead of UTF-8, I get '??' on the screen.

That you already said in the original post. My answer is still
the same.

Regards, Lothar
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!

Raga - 13 Oct 2006 11:23 GMT
Hi, Thanks for your reply. My system is Microsoft Windows XP. How do I
change its encoding? Can you please help?

Thanks.

> > 1. How do I change my system's default encoding?
>
[quoted text clipped - 25 lines]
> Always remember: The answer is forty-two, there can only be wrong
>                  questions!


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.