上代码:
package com.construn.vehiclenetty.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.ResourceBundle;
/**
* Created with IntelliJ IDEA.
*
* @author: zhangenke
* @Date: 2018/9/25 on 下午5:19
* @description:
*/
public class TestUtil {
public static void main(String[] args) throws IOException {
InputStream is = TestUtil.class.getClassLoader().getResourceAsStream("service.properties");
Properties p = new Properties();
p.load(is);
System.out.println(p);
// {zookeeper=localhost:2181, kafka=localhost:9092, message=http://localhost:8083/,
// vehicle=http://localhost:8080/}
System.out.println(p.get("vehicle"));
// http://localhost:8080/
ResourceBundle resourceBundle = ResourceBundle.getBundle("service");
System.out.println(resourceBundle);
// java.util.PropertyResourceBundle@5674cd4d
String vehicle = resourceBundle.getString("vehicle");
System.out.println(vehicle);
// http://localhost:8080/
}
}