警告:编码 UTF8 的不可投射字符
警告:编码 UTF8 的不可映射字符
再Build就正常了.
转载: http://qiang106.iteye.com/blog/526326
今天接手一个公司的老项目,刚从CVS上check out后用Ant Build的时候总是报“警告:“编码 UTF8
的不可映射字符”。看了下都是代码中的中文注释,因为我的Eclipse默认采用UTF-8的编码,而这个项目以前是用的GBK,改了一下项目的
properties,注释在代码中能正常显示了,但是Build的时候还是会报这个问题,想想以前刚学Java的时候也有见过这样的错误,手动编译
class的时候也有可有出现这种情况,那就在javac后面加一个编码参数,也就是java encoding XXX
x.java就可以了。这是因为编译的时候编码跟文件存储的编码方式不一样造成的,在网上找了些资料,有说在Ant的build.xml中加一
行<compilerarg line="-encoding XXX "/>
到<javac>,XXX就是希望使用的何中编码方式来编译,也就是给Javac添加一个compilerarg编译参数,实际效果就好像
javac -encoding XXX X.java,指定了编码方式,我需要用GBK编码,所以应该写成
- < compilerarg line = "-encoding GBK " />
<compilerarg line="-encoding GBK "/>,改好后的<javac>如下:
- < javac srcdir = "${src.home}" destdir = "${build.class}" debug = "yes" >
- < compilerarg line = "-encoding GBK " />
- < classpath refid = "compile.classpath" >
- </ classpath >
- </ javac >
<javac srcdir="${src.home}" destdir="${build.class}" debug="yes"> <compilerarg line="-encoding GBK "/> <classpath refid="compile.classpath"> </classpath> </javac>
再Build就正常了.
You can determine the current character encoding settings by means of the System class:
String currentEncoding = System.getProperty("file.encoding");
Or by means of the Charset class: Charset.defaultCharset()
You could change the default encoding used by your application by means of setting this variable when you lauch the application, for instance:
> java -Dfile.encoding=UTF-8
> java -Dfile.encoding=ASCII
> java -Dfile.encoding=UTF-16
> java -Dfile.encoding=Cp1252
> java -Dfile.encoding=Cp500
String currentEncoding = System.getProperty("file.encoding");
Or by means of the Charset class: Charset.defaultCharset()
You could change the default encoding used by your application by means of setting this variable when you lauch the application, for instance:
> java -Dfile.encoding=UTF-8
> java -Dfile.encoding=ASCII
> java -Dfile.encoding=UTF-16
> java -Dfile.encoding=Cp1252
> java -Dfile.encoding=Cp500