从eclipse导出java .jar时的Charset

时间:2014-07-22 07:33:23

标签: java build character-encoding

我正在开发一个使用德语特殊字符的应用程序(使用utf-8)。我已将eclipse中的工作区字符集设置为utf-8。当debbuging app特殊字符都正确显示时,但是在导出应用程序(runnable jar文件)并启动它时(通过双击浏览器,它会在尝试显示这些字符时显示垃圾)。 我做错了什么,我怎么能让它发挥作用?

提前致谢

1 个答案:

答案 0 :(得分:0)

当您使用与字符串编码相关的任何函数时,请明确使用charset参数,例如: 不要这样做:

String s = new String(bytes);

InputStreamReader is = new InputStreamReader(inputstream)

但请使用此:

String s = new String(bytes, Charset.forName("UTF-8"));

InputStreamReader is = new InputStreamReader(inputstream, "UTF-8")