首页 > 代码库 > Java基础知识

Java基础知识

1、Properties

(1)通过资源包ResourceBundle获得资源对象

<pre name="code" class="java">public class PropertiesTest {
	public static HashMap<String, Properties> hashMap = new HashMap<String, Properties>();
	public static String filename = "my";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		ResourceBundle bundle = ResourceBundle.getBundle("my");
		Properties properties = new Properties();
		Enumeration<String> enumeration = bundle.getKeys();
		while (enumeration.hasMoreElements()) {
			String key = enumeration.nextElement();
			String value = http://www.mamicode.com/bundle.getString(key);>

(2)通过输入流获得资源对象

		InputStream inputStream = getClass().getResourceAsStream(
				"/my.properties");
		Properties properties = new Properties();
		try {
			properties.load(inputStream);
			Enumeration<Object> enumeration = properties.keys();
			while (enumeration.hasMoreElements()) {
				String key = (String) enumeration.nextElement();
				String value = http://www.mamicode.com/properties.getProperty(key);>

Java基础知识