Friday 23 November 2007

Sun's javac and source file character encoding

Sometimes you may need to tell the Java compiler about the character encoding of the source files. For example, if an ISO-8859-1 encoded source file is compiled in a UTF-8 environment, any funny (non-ASCII) characters may become a problem.

This is an example of how you can tell Sun's javac about the source file encoding:


javac -encoding iso8859-1 <FILE PATH(s)>

(Without the encoding switch, javac uses your system's default encoding.)


This way, you can tell Sun's JVM to expect UTF-8 IO:
java -Dfile.encoding=utf8

No comments: