Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Problems Display Unicode Directly from Keyboard

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problems Display Unicode Directly from Keyboard

    Hi dear Java Community,

    I have developed many Java projects, but am working on my first Unicode project. I have searched the appropriate forum threads (such as, http://www.javaprogrammingforums.com...haracters.html, etc) and the internet, etc, but there does not appear to be much info on this subject.

    For test purposes, I have just a basic setup:

    1. My Java file is to UTF-8 encoding.

    2. A simple Java code as follows:

    public class TestUnicode {

    public static void main (String args[]) {
    System.out.println ("Trying to display unicode character: \u011f. Thanks");
    }

    }

    From command line using Java 1.6:

    javac -encoding UTF-8 TestUnicode.java

    (compiles fine, but upon running it...)

    java -Dfile.encoding=UFT8 TestUnicode

    I get the following:

    Trying to display unicode character: ─ƒ.

    (which is the incorrect character, however if, I run it without the encoding, then I get the following...)

    Trying to display unicode character: ?.

    (JVM getting confused even further or is it me?)

    Any ideas?


    Regards,
    Jamie


  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems Display Unicode Directly from Keyboard

    Hi,

    I have solved the problem:

    The Command Prompt (MSDOS Windows) needed to be set to UFT-8 encoding, which was accomplished by invoking..

    chcp 65001

    ..at the prompt. This sets the environment to UFT-8. Then I ran the Java program as UTF-8 as follows...

    java -Dfile.encoding=UFT8 TestUnicode

    Problem solved.

    Regards,
    Jamie

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems Display Unicode Directly from Keyboard

    ""The Command Prompt (MSDOS Windows) needed to be set to UFT-8 encoding, which was accomplished by invoking..

    chcp 65001

    ..at the prompt. This sets the environment to UFT-8.""

    may u please tell me how to do all this ?? i do not get , how to invoke and what to invoke ?? please tell !!

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems Display Unicode Directly from Keyboard

    Hi,

    Sure I can, but please do note that this is to run Java via a Command Prompt using MSDOS Windows:

    1. Each time you open up a DOS Window (by clicking on Start logo, then All Programs, then Accessories, then Command Prompt)

    2. Set the Window environment to Unicode by typing at the prompt:

    chcp 65001 (and then press the Enter/Return button)

    3. If you have written a Java program and lets say it's called TestUnicode.java, then type the following to compile the code:

    javac TestUnicode.java (and then press the Enter/Return)

    4. Then finally, to run the program called TestUnicode that has Unicode characters that are stored in Strings and Collections, then type the following:

    java -Dfile.encoding=UFT8 TestUnicode

    5. Assuming that your program displays the Unicode characters, then you will see at the DOS Window your Unicode characters being displayed correctly (hopefully).

    I hope the above helps.

    Take care...

    Kind regards,
    Jamie

Similar Threads

  1. Trying to display Unicode characters
    By kc120us in forum What's Wrong With My Code?
    Replies: 12
    Last Post: January 16th, 2012, 05:55 PM
  2. Replies: 2
    Last Post: November 2nd, 2011, 10:48 AM
  3. Directly Click the pdf File and my Java application will run
    By Jhovarie in forum Java Theory & Questions
    Replies: 2
    Last Post: May 3rd, 2011, 08:48 AM
  4. Problem with directly and indirectly access system command
    By silentbang in forum Java Theory & Questions
    Replies: 0
    Last Post: January 29th, 2011, 11:34 AM
  5. [SOLVED] can't run javac directly from command prompt
    By epezhman in forum Java IDEs
    Replies: 7
    Last Post: January 12th, 2011, 07:38 PM