标签:hold ati nss ace 引入 pre 配置 gets sys
public class ResourceUtil {
private static final ResourceBundle bundle = java.util.ResourceBundle
.getBundle("sysConfig");
public static final String getConfigByName(String name) {
String value = "";
try {
value = new String(bundle.getString(name).getBytes("iso8859-1"),
"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return value;
}
}
public void testPro() throws IOException{
InputStream insss =this.getClass().getResourceAsStream("/conf/resources.properties");
Properties pss = new Properties();
pss.load(insss);
System.out.println(pss.getProperty("IMAGE_SERVER_URL"));
}
public void testPro() throws IOException{
InputStream insss =Object.class.getResourceAsStream("/conf/resources.properties");
Properties pss = new Properties();
pss.load(insss);
System.out.println(pss.getProperty("IMAGE_SERVER_URL"));
}
public class testProperties extends TestCase{
public void testPro() throws IOException{
Resource resource = new ClassPathResource("/conf/resources.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);
System.out.println(props.getProperty("IMAGE_SERVER_URL"));
}
}
xml配置文件中引入的:
<context:property-placeholder location="classpath:conf/resources.properties" />
@Value("${IMAGE_SERVER_URL}")
private String IMAGE_SERVER_URL;
ResourceBundle的方式 ,传入一个inStream
ResourceBundle resource = new PropertyResourceBundle(inStream);
InputStream inStream = new FileInputStream(new File("filePath"));
InputStream in = context.getResourceAsStream("filePath");
方法⑨:ulr方式读取
URL url = new URL("path");
InputStream inStream = url.openStream();
Properties prop = new Properties();
prop.load(inStream);
String key = prop.getProperty("username");
String key = (String) prop.get("username");
标签:hold ati nss ace 引入 pre 配置 gets sys
原文地址:https://www.cnblogs.com/lan-syy/p/14354613.html