File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How do I print extended ascii characters in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do I print extended ascii characters in Java " Watch "How do I print extended ascii characters in Java " New topic
Author

How do I print extended ascii characters in Java

Samuel Thomas
Greenhorn

Joined: Nov 08, 2000
Posts: 4
Hello
I would like to print extended ascii characters(characters between 127 and 255). Unfortunately I am not able to get the corresponding ascii character symbols for the following values 129,141,143,144,157. I am getting the correct values for all the other numbers,
except for these numbers where a ? is returned.
for( int i=127;i < 256;i++)
{
byte[] data = new byte[1];
data[0]= (byte)i;
System.out.println("The character " + new String(data));
}
Could any one tell me where I went wrong ?
Please do help me with an idea of getting the values for the missed numbers?
Thanking you in advance
Regards
Samuel
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
There's more than one "extended ASCII" out there. Probably the default encoding on your machine is different from what you are expecting. Instead use the String constructor that allows you to specify an encoding:
<code><pre> System.out.println(new String(data, "US-ASCII"));
System.out.println(new String(data, "ISO-LATIN-1"));
</pre></code>
For comparison, you can find out the name of the default encoding on your system with
<code><pre> System.out.println("Default: " + new InputStreamReader(System.in).getEncoding());</pre></code>
More info on encoding can be found here and here.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I print extended ascii characters in Java