forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageFormatDemo.java
More file actions
27 lines (23 loc) · 823 Bytes
/
MessageFormatDemo.java
File metadata and controls
27 lines (23 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package onlyfun.caterpillar;
import java.util.ResourceBundle;
import java.text.MessageFormat;
public class MessageFormatDemo {
public static void main(String[] args) {
try {
// 綁定messages.properties
ResourceBundle resource =
ResourceBundle.getBundle("messages2");
String message = resource.getString(
"onlyfun.caterpillar.greeting");
Object[] params =
new Object[] {args[0], args[1]};
MessageFormat formatter =
new MessageFormat(message);
// 顯示格式化後的訊息
System.out.println(formatter.format(params));
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println("沒有指定引數");
}
}
}