【问题标题】:Not able to Build .ear file to have Text file encoding=UTF-8无法构建 .ear 文件以具有文本文件编码 = UTF-8
【发布时间】:2013-07-02 19:52:43
【问题描述】:

我有一些处理汉字的代码。在我的 Eclipse 中,我设置了项目 -> 属性 -> 资源 -> 文本文件 encoding = UTF-8。我使用javac.encoding=UTF-8 通过 ANT 构建我的 .ear。在 Websphere7 中运行我的 .ear 时。但不知何故,文本文件不再编码为 UTF-8。

问题是在UTF-8中,String.getBytes().length每个汉字都会返回3,但是没有UTF-8,所有汉字都会变成“?”,所以String.getBytes().length每个汉字都会返回1 .我需要找到一种方法让它返回 3。

我错过了什么? Websphere 中是否有我需要设置的设置?

谢谢,

【问题讨论】:

    标签: java ant utf-8 websphere


    【解决方案1】:

    你是如何阅读文件的?您是否使用 UTF-8 字符集阅读?

    InputStream stream = Thread.currentThread()
            .getContextClassLoader().getResourceAsStream("com/app/myfile.txt");
    InputStreamReader streamReader = new InputStreamReader(stream, "UTF-8");
    BufferedReader reader = new BufferedReader(streamReader);
    

    【讨论】:

    • 实际上我正在运行 SOAP 客户端以从第 3 方公司 SOAP 服务器中提取数据。数据为中文。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多