我必须打印阿拉伯字符串(我正在使用TestNG框架)。我的代码是这样的:
@Test
public void test() throws UnsupportedEncodingException{
String countryString = "المملكة العربية السعودية";
String utfCountryString = new String(countryString.getBytes(), "utf-8");
System.out.println("UTF String : "+utfCountryString);
System.out.println("Original String : "+countryString);
}但是,当我使用TestNG运行它时,我得到了以下输出:
UTF String : ??????? ??????? ????????
Original String : ??????? ??????? ????????
PASSED: test
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================但是,如果我在main()方法下运行它或使用jUnit,输出就会非常好。
请告诉我如何使用TestNG运行它。谢谢。
发布于 2015-09-10 07:09:42
当未为UTF-8编码定义对java编译器的文件编码时,会出现问题.正如您提到的,您正在使用Ant作为构建工具,请在build.xml文件中定义以下编码。
<javac ... encoding="UTF-8" ... />对我来说测试和工作都很好。
发布于 2016-11-24 10:34:30
试着在构建文件中粘贴以下内容:
<javac debug="true" debuglevel="${debuglevel}" destdir="${classes.dir}" encoding="UTF-8"
includeantruntime="false" source="${source}" target="${target}"
srcdir="src">
<src path="src" />
<classpath refid="Dummy.classpath" />
</javac>https://stackoverflow.com/questions/32396779
复制相似问题