4

When I tried to compile (use javac)some java sources files include a comment line which has some unrecognized char like ascii code 129 (~A), error got.

The sources code looks like the following:

 // ascii 129 is ? (Acutally it show ~A in VIM but show ? when I directly copy it here)

The above code line is a comment, it should not cause any error, but if it did, I think it should be a problem about the jave encode form, how can I solve this problem?

Thanks.

Wa

user1232236
  • 207
  • 1
  • 4
  • 10
  • `129` is not a valid ASCII code. ASCII only goes up to `127`. Codepoint `129` is also reserved and undefined in `ISO-8859-1` which Unicode is a superset of. It is also undefined in `Windows-1252` which is popular on Windows on computers in the western world. In short, it does not represent a character in some of the most popular encodings, so i'm really curious which encoding was used to encode the Java source file in question. – Christoffer Hammarström Mar 27 '12 at 15:52

2 Answers2

2

Take a look at this answer. It worked for me, and I don't have to worry about it anymore :) https://stackoverflow.com/a/623036/971592

Community
  • 1
  • 1
kentcdodds
  • 27,113
  • 32
  • 108
  • 187
0

Pick the correct encoding of the java source. UTF-8 would be a good requirements standard. One can use the open source editor JEdit to test which encoding the source actually is in. The java tool native2ascii can convert.

javac -encoding UTF-8 ...
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • 1
    How to change the default system encode form so that I don`t have to add "-encoding xxx" after javec everytime? – user1232236 Mar 12 '12 at 06:07
  • Use a build system, like the easy **maven**, where you can configure the encoding once. An IDE, like NetBeans, would provide editing in some encoding, and compiling in some encoding too. The problem of editing in some non-default encoding does not seem worth changing the Windows encoding. You can associate in Windows .java with an editor/compiler with encoding command-line parameter. – Joop Eggen Mar 12 '12 at 15:59
  • 6
    I found a solution, in Windows, set a system variable JAVA_TOOL_OPTIONS to be "-Dfile.encoding=UTF-8", it will work. – user1232236 Mar 13 '12 at 04:26