We have an application that outputs the £ ( pound) sign correctly when the application is run on the Mac but outputs a ? ( question mark ) when run on test server.
Below is sample of the code and generated output
LOGGER.debug(" TESTING file.encoding=" + System.getProperty("file.encoding"));
LOGGER.debug(" TESTING Charset.defaultCharset=" + Charset.defaultCharset());
try {
LOGGER.debug(" TESTING InputStreamReader.getEncoding=" + new InputStreamReader(new FileInputStream("/tmp/PrintCharSets.java")).getEncoding() );
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String pound = "£";
LOGGER.debug(
" TESTING - 0 - Test Character [" + pound + "]");
Output On Test Server
TESTING file.encoding=UTF-8
TESTING Charset.defaultCharset=US-ASCII
TESTING InputStreamReader.getEncoding=ASCII
TESTING - 0 - Test Character [?]
Output On My Mac
TESTING file.encoding=UTF-8
TESTING Charset.defaultCharset=UTF-8
TESTING InputStreamReader.getEncoding=UTF8
TESTING - 0 - Test Character [£]
I suppose this is due to encoding of the string. We can see there is a difference in the defaultCharset and encoding. However, would you be able to advice how I can get the £ sign to be outputted correctly on the test server via making changes in the code.
This application will run on different servers so I can't assume the encoding is consistent.