how do I set the encoding for javac ?

F

Frank Gerlach

I have some trouble with javac: The string constants I use contain
characters, with codes larger than the ASCII maximum.
Example:

public class language{
public static void main(String[] argv){
System.out.println("möglich");
}
}

generates this output:

m÷glich

How do I configure javac to use a different charset, eg. "ISO8859-1" ?
 
C

Collin VanDyck

Frank said:
I have some trouble with javac: The string constants I use contain
characters, with codes larger than the ASCII maximum.
Example:

public class language{
public static void main(String[] argv){
System.out.println("möglich");
}
}

generates this output:

m÷glich

How do I configure javac to use a different charset, eg. "ISO8859-1" ?

I don't think it's a problem with javac, but rather a problem with the
console to which you are outputting at runtime. I know that the windows
CMD prompt does not display UNICODE correctly for me, and one way you
can get around this is to instead log to a file using a FileWriter and
then open up the file in a text editor or log viewer that supports the
charset you are using to output.

The FileWriter assumes a default character encoding which you can
override when running the program by saying:

% java -Dfile.encoding="ISO8859-1" language

If you cannot change the way in which the class is invoked, you can
create an OutputStreamWriter on a FileWriter and specify the character set.

HTH
 
J

John C. Bollinger

Frank said:
I have some trouble with javac: The string constants I use contain
characters, with codes larger than the ASCII maximum.
Example:

public class language{
public static void main(String[] argv){
System.out.println("möglich");
}
}

generates this output:

m÷glich

How do I configure javac to use a different charset, eg. "ISO8859-1" ?

d:\>javac -help
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is
doing
-deprecation Output source locations where deprecated
APIs are used
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files

[Note below:]

-encoding <encoding> Specify character encoding used by source files


-source <release> Provide source compatibility with specified
release
-target <release> Generate class files for specific VM version
-help Print a synopsis of standard options


d:\>


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top