This is a rudimentary question.My current original file is SJIS.So, I want to display Japanese kanji on the Linux screen.
My current Java source code is:
private static String convertUTF8ToShiftJ(String uft8Stg){
String is = null;
String shftJStrg = null;
try{
byte [] bt = uft8Strg.getBytes (StandardCharsets.UTF_8);
is = new String(bt, "SHIFT-JIS");
shftJStr = new String(is);
logger.info("Converted to the string:"+shftJStrg);
System.out.println(shftJStrg);
} catch(Exceptione){
e.printStackTrace();
return uft8Strg;
}
return shftJStrg;
}
In , the results displayed on the Linux screen are:
***UX0025.SH 開Started )
*** UX0025.SH � (executing...ec)
*** UX0025.SH 終Endedツ
However, the actual results you want to see are:
***UX0025.SH Start (started)
*** UX0025.SH Running...
*** UX0025.SH Ended
I'm in trouble because I don't know where my code is wrong.
Does anyone know?It's helpful.
The proposed convertUTF8ToShiftJ()
uses the Unicode string as input and encodes it into the UTF-8 byte string, forcing it to be decoded as shift JIS and returning it to Unicode.Non-ASCII characters will be corrupted.
Java String
is always Unicode, so
This should be the expected behavior.
© 2024 OneMinuteCode. All rights reserved.