I have an app developed with Java
. When I test it in Eclipse
, it works perfectly. Every characters is perfect, but when I compile and export the jar and test it with the OS X terminal, the strange characters (I'm spanish) are wrong. They are a "?".
I think I use UTF-8
everywhere, so I dont know what to do.
Thanks
Most likely, you are not using UTF-8 everywhere, but have some code that defaults to the platform encoding (which in turn can be set by environment variables and is likely different between Eclipse, where it is set to match the workspace file encoding and your shell).
Make sure you explicitly have "UTF-8" as the charset in all character conversions (such as opening readers) in your code.
For example, don't use
Reader r = new FileReader("a.txt");
use
Reader r = new InputStreamReader(new FileInputStream("a.txt"), "UTF-8");
If that is not possible, the short-term solution would be to set the appropriate environment variables or system properties (I think -Dfile.encoding=UTF-8
).
Check your locale using locale
command on the terminal. The strings printed should contain .UTF-8
, .utf8
or a similar suffix. If they don't, you're using a non-UTF-8 locale and the output of your app is not displayed properly. I'm not sure which locales will be available, but you can try running export LC_ALL=es_ES.UTF-8
before you run the app, and check if that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.