Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2006

Tip: Looking for answers? Try searching our database.

Problems with saving .java file as UTF-8

Thread view: 
typingcat@gmail.com - 29 Sep 2006 02:30 GMT
-----------------test.java-------------------------
public class test
{
    public static void main(String[] args)
    {
        System.out.println("学校,한국어");
    }

}
----------------------------------------------------
I saved it as UTF-8 then compiled it with,
javac test.java -encoding utf-8
It compiled successfully but when I ran it, the output was
??,???
This is not what I expected, the output should have been,
学校,한국어

What do you think I did wrong?

Plus, when I edited the java file with Notepad, it seems like
BOM(Byte Order Mark) is added. But then the javac says,
javac test.java -encoding utf-8
test.java:1: illegal character: \65279
癤퓈ublic class test
^
1 error

How can I make javac understand BOM using UTF-8?

Thank you.
Thomas Weidenfeller - 29 Sep 2006 08:32 GMT
> -----------------test.java-------------------------
> public class test
[quoted text clipped - 7 lines]
> ----------------------------------------------------
> I saved it as UTF-8 then compiled it with,

Which is in general not a very clever idea. If you are interested in
maximum source code portability and least trouble with tools use only
Latin-1 or better yet ASCII in Java source code. Add everything outside
this range via Unicode escape sequences \uxxxx. Better yet, externalize
all such strings and use a resource bundle (which must be in ASCII or
Latin-1 and contain Unicode escape sequences).

When doing so, the JDK tool native2ascii and a decent build system are
your friends to generate the files with the escape sequences.

> javac test.java -encoding utf-8
> It compiled successfully but when I ran it, the output was
> ??,???
> This is not what I expected, the output should have been,
> 学校,한국어

You don't have the right font, or you have a mismatch between the
console's font encoding and the System.out's font encoding.

May I suggest that you reserve a few hours and study Sun's
internationalization tutorial, plus their information regarding font
handling?

> Plus, when I edited the java file with Notepad, it seems like
> BOM(Byte Order Mark) is added. But then the javac says,
[quoted text clipped - 3 lines]
> ^
> 1 error

As I wrote, storing Java source code in anything but ASCII or Latin-1 is
not really a clever idea.

/Thomas
Signature

The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.