问题
I've almost tried everything including:
- Change system region and language to be 'english US'
- Use Locale.setDefaultLocale()
- Pass in JVM arguments
It prints out:
Default locale is : en_US
BUT my application is still throwing exception with Chinese exception message
Does this have anything to do with Spring? (my app is based on Spring, but there is no locale-related config whatsover, so it should be just using whatever is default)
Can anyone help me with this?
UPDATE:
I'm basically getting a java.io.IOException
with Chinese message equivalent to
An existing connection was forcibly closed by the remote host
changing the locale didn't seem to affect this, maybe this is indeed an OS level thing?
回答1:
"An existing connection was forcibly closed by the remote host" is a standard error message from the Windows Sockets library (code 10054).
In retrieving the error message for the error code, the specification of the FormatMessage function says it will take the user or system locale into account. As far as I know, setting the system region and language to English US should do that. Perhaps a Chinese version of Windows just doesn't have English language messages available?
回答2:
Throwable.getLocalizedMessage() might work, assuming that the library you're using provides localized exception messages.
来源:https://stackoverflow.com/questions/17159357/is-there-a-way-to-force-exception-message-to-be-english-for-java-1-7