获取.properties后缀的数据
生活随笔
收集整理的這篇文章主要介紹了
获取.properties后缀的数据
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在MyPro.properties中的數(shù)據(jù)如下:
Name=ABC
測試類中:
Properties properties = new Properties();
String configFile = "MyPro.properties";
//將MyPro.properties文件編譯成文件流
InputStream is = ConfigManager.class.getClassLoader().getResourceAsStream(configFile);
try {
//用Properties 類載入流文件
properties.load(is);
//關(guān)閉文件流
is.close();
} catch (IOException e) {
e.printStackTrace();
}
//用getProperty方法就可以得到MyPro.properties中的屬性
System.out.println(properties.getProperty("Name"));
在控制臺輸出的結(jié)果為:
ABC
轉(zhuǎn)載于:https://www.cnblogs.com/mymbs/p/8656777.html
總結(jié)
以上是生活随笔為你收集整理的获取.properties后缀的数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 孕妇梦到麻雀是什么意思
- 下一篇: 词频统计预处理之综合练习