export LANG=ZH_cn.GBK
nohup /home/jdk1.6.0_17/bin/java -Dfile.encoding=GBK -Xms200m -Xmx400m -classpath "/home/icehome/search2010/classes" -Djava.ext.dirs=/home/icehome/search2010/lib com.tmg.search.service.indexer.IndexSpider &
在startIndexer2010.sh中添加環境變量-Dfile.encoding=GBK 問題解決。
其原因在于String.getBytes()時實際調用StringCoding.encode(value, offset, count)方法,其中使用默認編碼Charset.defaultCharset().name()。defaultCharset從環境變量 file.encoding中取值。
故設置環境變量-Dfile.encoding=GBK 改變默認編碼