Java 测试不同字符集的长度

你可以用下面的方法测试下不同类型的编码的字符显示长度。[code]package net.hawebs.dbSync.test;

import java.io.UnsupportedEncodingException;

/**

  • 测试类
  • @author YUCHENGHU

*/
public class HTest {

public static void main(String[] args) {
	String aString = "罕布什尔(中国)信息技术有限公司 ,This is a test string.";
	String anotherString = null;
	try {
		anotherString = new String(aString.getBytes("UTF-8"), "ISO8859_1");
	} catch (UnsupportedEncodingException ex) {
	}
	System.out.println(aString.length() + "," + anotherString.length());
}

}[/code]运行结果如下: