Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unicode characters  RSS feed

 
venkatesh pendharkar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Java uses all 65536 Unicode characters that are avaibles.Still why is it that we are only able to print first 256 characters on command line or in the text file.eg.
import java.io.*;
class D
{
char c;
D()
{
c=0;

}
public static void main(String args[])
{
D d=new D();
d.met();
}
void met()
{
try
{
FileOutputStream fi=new FileOutputStream("unicode.txt");
for (int i=0;i<65536;i++ )
{
fi.write(i);
}
fi.flush();
fi.close();

}
catch (FileNotFoundException e)
{
}
catch (IOException e)
{
}
}
}

in this code only first 256 characters are written again & again.Is the printing of characters dependent upon OS?
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the javadoc for write(int) method:
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.
So why does it take an int instead of a byte? I've never understood that.
 
venkatesh pendharkar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe for your help.The link given by you was really helpful in understading basics of encoding.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!