Java Properties

package com.test.base.classloader;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

import org.junit.Test;

public class TestClassLoader {
	@Test
	public void testClassLoaderGetProperty() {
		String filePath = "/test.properties";
		InputStream intpuStream = ClassLoader.class.getResourceAsStream(filePath);
		Properties properties = new Properties();
		HashMap map = new HashMap();
		try {
			properties.load(intpuStream);
			
			Set<Entry<Object, Object>> entrySet = properties.entrySet();
			for (Entry<Object, Object> entry : entrySet) {
				System.out.println(entry.getKey()+ " = " + entry.getValue());
				map.put(entry.getKey(), entry.getValue());
			}
				
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}
}

猜你喜欢

转载自dannyhz.iteye.com/blog/2235551