java常用类库:国际化&处理动态文本示例

package com.xdl.dcy.java10122;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Scanner;

public class I18NDemo3 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Locale locale = Locale.CHINA;
		ResourceBundle res = ResourceBundle.getBundle(
				"com.xdl.dcy.java10122.info", locale);
		while (true) {
			Scanner sc = new Scanner(System.in);
			System.out.println(res.getString("sys.userName"));
			String name = sc.next();
			System.out.println(res.getString("sys.password"));
			String password = sc.next();

			String welcome = MessageFormat.format(res.getString("sys.welcome"),
					name);

			if ("admin".equals(name) && "123".equals(password)) {
				System.out.println(welcome);
				System.out.println(res.getString("sys.add"));
				System.out.println(res.getString("sys.del"));
				System.out.println(res.getString("sys.update"));
				System.out.println(res.getString("sys.query"));
				break;
			} else
				System.out.println(res.getString("sys.err"));
		}

	}

}

你可能感兴趣的:(java常用类库:国际化&处理动态文本示例)