I am having this encoding issue in java, one string I actually need to handle is the response from running "systeminfo" command under windows commandline, and I need to present the result in a html document. The problem is if I run my application on French operating system, the garbled characters are shown in the html, no matter how I tried to convert the encodeing settings.
From the log, I can see the system encoding is "Cp1252", code snippet is as follows:
String systemEncoding = System.getProperty("sun.jnu.encoding");
log.info("sun.jnu.encoding="+systemEncoding);
In html builder class, I did something like this:
for(String line : lines){
line = new String(line.getBytes("Cp1252"), "UTF8");
osReport.append(line + "<br>");
}
Unfortunately, I still can see those garbled "question marks" all around, which are supposed to be some French characters.. The html header looks like this btw
<HEAD>
<META content="text/html; charset=UTF-8" http-equiv=Content-Type>
</HEAD>
How to get the response string, see the following piece of code please..
try{
String systemEncoding = System.getProperty("sun.jnu.encoding");
log.info("sun.jnu.encoding="+systemEncoding);
InputStreamReader isr;
if (StringUtil.isEmpty(systemEncoding)) {
isr = new InputStreamReader(is);
} else {
isr = new InputStreamReader(is, systemEncoding);
}
BufferedReader br = new BufferedReader(isr);
String line=null;
while ((line = br.readLine()) != null) {
res.append(line);
res.append(LINE_SEP);
}
} catch (IOException ioe) {
log.error("IOException occurred while printing the response",ioe);
}
Any help?? Thanks so very much!
line = new String(line.getBytes("Cp1252"), "UTF8");fromUTF8toUTF-8. Perhaps that's the problem?