Difference in int cast to char between Windows and redhat linux 9 under JDK 1.4.2_06

P

Private

Difference in int cast to char between Windows and redhat linux 9 under JDK
1.4.2_06

With regards to the following; how can I control the charset used for the
cast ? The desired outcome would be for 0x80 to cast to '\u0080'. At
the least I need to be able to run consistently across the two platforms.

Thanks to all for any help on this.

<java code CharTester fragment>

FileInputStream fis=new FileInputStream(args[0]);

for (int i=fis.read();i>-1;i=fis.read())
System.out.print((char)i);

System.out.flush();
fis.close();

</fragment>

<test run under linux>

# hexdump -C < print.doc
00000000 7e 7f 80 81 fc fd ff |~......|
00000007

# java com.asl.hacks.CharTester print.doc
# java com.asl.hacks.CharTester print.doc | hexdump -C
00000000 7e 7f c2 80 c2 81 c3 bc c3 bd c3 bf |~...........|
0000000c

</test>

under windows the same command produces

7e 7f 3f 3f fc fd ff
 
A

Alex Kizub

under windows the same command produces
7e 7f 3f 3f fc fd ff

You use none ASCII characters. Read more about InputStream and Readers and what
is the difference betwen them.
Also check what is the locale on your Windows and Linux systems. I bet they are
different.

Alex Kizub.
 
M

Michael Borgwardt

Private said:
Difference in int cast to char between Windows and redhat linux 9 under JDK
1.4.2_06
No.

With regards to the following; how can I control the charset used for the
cast ?

There is no charset involved in such a cast, both are integer types.
The desired outcome would be for 0x80 to cast to '\u0080'.

And that is what will happen. Always.
<java code CharTester fragment>

FileInputStream fis=new FileInputStream(args[0]);

for (int i=fis.read();i>-1;i=fis.read())
System.out.print((char)i);

Ah, well this is a different thing. You are reading the byte values and
interpreting them as unicode code points. That's equivalent to using
the ISO-8859-1 charset.

But the platform dependence is not in the casting from int, it's in the
call of print(), which uses the platform default encoding to convert the
character back to bytes, which then appear on the program's standard
output.

What is the program supposed to do, anyway?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top