java多语言编程,如何在Java应用程序中处理多种语言?

I am writing a program use JSP and Java. How can I use property files to support multiple languages?

And by the way, there are always some things like \u4345.

What is this? How do they come?

解决方案

For the multiple languages, check out the ResourceBundle class.

About the \u4345, this is one of the dark and very annoying legacy corners of Java. The property files need to be in ASCII, so that all non-ASCII characters need to encoded as \uxxxx (their Unicode value). You can convert a file to use this encoding with the native2ascii command line tool.

If you are using an IDE or a build tool, there should be an option to invoke this automatically.

If the property file is something you have full control over yourself, you can starting from Java6 also use UTF-8 (or any other character set) directly in the property file, and specify that encoding when you load it:

// new in Java6

props.load(new InputStreamReader(new FileInputStream(file), 'UTF-8'));

Again, this only works if you load the Properties yourself, not if someone else does it, such as a ResourceBundle (used for internationalization).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值