java 读取 .properties 文件

public class PropertiesUtils {

	public static Properties getProperties() {

		Properties p = new Properties();

		try {
			InputStream inputStream = PropertiesUtils.class.getClassLoader().getResourceAsStream( "/config-file/APIConfig.properties" );

			p.load( inputStream );

		} catch ( IOException e1 ) {
			e1.printStackTrace();
		}

		return p;
	}

}
API_SERVER_HOST = api.server.host.com

    常量方式调用

public static String API_SERVER_HOST = PropertiesUtils.getProperties().getProperty( "API_SERVER_HOST" );

猜你喜欢

转载自colin-davis.iteye.com/blog/2245542