943,786 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 992
  • Java RSS
Dec 11th, 2008
0

Need help on Unicode (GURMUKHI) in java

Expand Post »
Hello everyone,

Im trying to write Punjabi (Gurmukhi) by Unicode. I have the Unicode code point of all character and Code Block is Gurmukhi.

java Syntax (Toggle Plain Text)
  1. System.out.prinln("\u0A73")
u0A73 = GURMUKHI URA = ੳ

but its showing "?".

then i tried with PrintStream

java Syntax (Toggle Plain Text)
  1. String unicodeMessage = "\u0A73";
  2. try {
  3. PrintStream output = new PrintStream(System.out, true, "UTF-8");
  4. output.print(unicodeMessage);
  5. } catch (UnsupportedEncodingException e) {
  6. e.printStackTrace();
  7. }
now its showing "ੳ".

Tried with UTF-16 and UTF-32 too.

so, i decided to post here for help. can anyone help me to sort out this problem ?

Thanks in advance.
Last edited by puneetkay; Dec 11th, 2008 at 9:56 am.
Reputation Points: 51
Solved Threads: 24
Junior Poster
puneetkay is offline Offline
122 posts
since Nov 2007
Dec 12th, 2008
0

Re: Need help on Unicode (GURMUKHI) in java

There is as such no problem with your code; IMO the fault lies with the incompetence of the shell to render fonts correctly. I assume you are on a windows box? Anyways, this is just a rendering issue. Maybe a little more background on what you are trying to achieve here would be required to offer some advice.

Anyways, to mess around with code points and to get a feel of how the characters looks, try this sample snippet which creates an HTML document 'test.html'.
Java Syntax (Toggle Plain Text)
  1. // Error handling and best practices omitted for brevity
  2.  
  3. public class HtmlTester {
  4.  
  5. private final static String HTML =
  6. "<html><head><META HTTP-EQUIV=\"Content-Type\" " +
  7. "CONTENT=\"text/html; charset=UTF-8\"></head><body><div>{0}" +
  8. "</div></body></html>";
  9.  
  10. public static void main(final String[] args) throws Exception {
  11. testIt();
  12. }
  13.  
  14. public static void testIt() throws Exception {
  15. String toWrite = MessageFormat.
  16. format(HTML, String.valueOf("\u0A72 \u0A73 \u0A74"));
  17. writeData(toWrite, new File("test.html"));
  18. }
  19.  
  20. public static void writeData(String s, File f) {
  21. try {
  22. BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
  23. new FileOutputStream(f), "utf-8"));
  24. out.write(s);
  25. out.flush();
  26. out.close();
  27. } catch(Exception e) {
  28. e.printStackTrace();
  29. }
  30. }
  31.  
  32. }
The gurmukhi characters are displayed correctly since I guess browsers have their own font rendering engine.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Dec 12th, 2008
0

Re: Need help on Unicode (GURMUKHI) in java

Hello,

Thanks for reply,
Actually, im creating a virtual Punjabi keyboard. On swing components, I used setFont() method and working perfectly. But i also need to display it on Console.

Im using Windows Vista and Eclipse IDE.

Im still on it, hope to the solution soon.

Thanks again!
Reputation Points: 51
Solved Threads: 24
Junior Poster
puneetkay is offline Offline
122 posts
since Nov 2007
Dec 12th, 2008
1

Re: Need help on Unicode (GURMUKHI) in java

If you plan on viewing the output on Eclipses's console, it shouldn't be that big a problem. Try following the advice in this post.

But if you are stuck with windows console, then there isn't a reliable / sure shot way of getting it to work. Many have suggested setting the code page to 65001 though I am not very sure whether it works in all cases.

Let me know if the above suggested fixes work in your case. Best of luck for your project; hoping to see it on sourceforge. ;-)
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Dec 13th, 2008
1

Re: Need help on Unicode (GURMUKHI) in java

Hie again,

It works! Thanks

Yea sure, I will surely post it on SourceForge

Thanks again!
Reputation Points: 51
Solved Threads: 24
Junior Poster
puneetkay is offline Offline
122 posts
since Nov 2007
Dec 13th, 2008
0

Re: Need help on Unicode (GURMUKHI) in java

So, were you trying it on Eclipse or windows console? BTW, bump this thread when your project is completed. :-)
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Dec 13th, 2008
0

Re: Need help on Unicode (GURMUKHI) in java

Click to Expand / Collapse  Quote originally posted by ~s.o.s~ ...
So, were you trying it on Eclipse or windows console? BTW, bump this thread when your project is completed. :-)
On Eclipse

bump this thread ?? didnt get you ..
Reputation Points: 51
Solved Threads: 24
Junior Poster
puneetkay is offline Offline
122 posts
since Nov 2007
Dec 13th, 2008
0

Re: Need help on Unicode (GURMUKHI) in java

I meant post a reply here once it is completed and up on sourceforge, so that I can get a notification; it might interest the kids new to Java.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Dec 13th, 2008
0

Re: Need help on Unicode (GURMUKHI) in java

Click to Expand / Collapse  Quote originally posted by ~s.o.s~ ...
I meant post a reply here once it is completed and up on sourceforge, so that I can get a notification; it might interest the kids new to Java.
Oh yea sure! I will surely notify you and post here too.
Reputation Points: 51
Solved Threads: 24
Junior Poster
puneetkay is offline Offline
122 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How do I concatenate this string
Next Thread in Java Forum Timeline: where to find the source codes...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC