找到一个方法的调用,该方法将执行字节到String(或String to byte)转换,并假设默认平台编码是合适的。这将导致应用程序行为在平台之间变化。使用备用API并明确指定charset名称或Charset对象。
try {
OutputStream outputStream = pResponse.getOutputStream();
if (ticketList != null && !ticketList.isEmpty()) {
outputStream.write(ticketList.getBytes());
outputStream.flush();
outputStream.close();
}
} catch (IOException e) {
Logger.logInfo(getClass(), "ticket list download", e);
Logger.logError(getClass(), "ticket list download",
e.getMessage());
}
如何解决此问题?
答案 0 :(得分:3)
您需要明确定义要使用的字符集。通常UTF-8是一个不错的选择。
try {
Charset charset = Charset.forName("UTF-8");
OutputStream outputStream = pResponse.getOutputStream();
if (ticketList != null && !ticketList.isEmpty()) {
outputStream.write(ticketList.getBytes(charset));
outputStream.flush();
outputStream.close();
}
} catch (IOException e) {
Logger.logInfo(getClass(), "ticket list download", e);
Logger.logError(getClass(), "ticket list download",
e.getMessage());
}