从 Windows 到 Linux 的 Http 响应解码行为不同

Http response decoding behaves differently from Windows to Linux

我的 java 应用程序正在从 UTF-8ISO-8859-1位桶存储库。
我事先知道这些文件中使用的字符集。

我的应用程序 运行 在我的 Windows 本地机器上运行良好(我将 Eclipse JEE 与 Tomcat 9 服务器一起使用)。

我已经在 RedHat 虚拟机 运行 上部署了这个应用程序 Tomcat 和 我最终用未知字符 替换了这些 é/è/à/ù/ï.


这是我为获取此数据而编写的代码:
public static String getFileContentFromRepository(String url) throws IOException {
        HttpURLConnection connection = getConnection(url);
        connection.connect();

        //The following function returns the charset of the file. (Proven to work)
        Charset repoCharset = getCharset();

        InputStream connectionDataStream = connection.getInputStream();
        String connectionStreamData = IOUtils.toString(connectionDataStream, repoCharset);
        
        connection.disconnect();

        return connectionStreamData;
}

如何在两个平台上获得相同的结果?

问题来自 Linux 将其默认字符集设置为 UTF-8。
在 Tomcat 的配置中将参数 -Dfile.encoding=ISO-8859-1 添加到 $CATALINA_OPTS 解决了我的问题。