資源簡介
Java 讀取屬性文件的單個屬性值(基礎篇-實例440).zip
代碼片段和文件信息
import?java.io.*;
import?java.util.*;
public?class?GetProperties?{
????
????public?String?getProperties(String?keyName)?{
????????InputStream?ins?=?getClass().getResourceAsStream(
????????????????“ApplicationResources.properties“);?//?根據屬性文件創建InputStream對象
????????Properties?props?=?new?Properties();?//?創建Properties對象
????????String?value?=?““;
????????try?{
????????????props.load(ins);?//?從輸入流中讀取屬性文件中信息
????????????value?=?props.getProperty(keyName);?//?獲取指定參數的屬性值
????????}?catch?(IOException?e)?{
????????????
????????????e.printStackTrace();
????????}
????????return?value;
????}
????
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????301??2010-09-10?15:22??.classpath
?????文件?????????379??2010-09-10?15:22??.project
?????文件?????????629??2010-09-10?15:22??.settings\org.eclipse.jdt.core.prefs
?????文件?????????143??2010-09-10?15:22??bin\ApplicationResources.properties
?????文件????????1080??2013-11-21?08:42??bin\GetProperties.class
?????文件?????????737??2013-11-21?08:42??bin\GetPropertiesfr
?????文件????????2453??2013-11-21?08:42??bin\GetPropertiesfr
?????文件?????????143??2010-09-10?15:22??src\ApplicationResources.properties
?????文件?????????655??2010-09-10?15:22??src\GetProperties.java
?????文件????????3236??2010-09-10?15:22??src\GetPropertiesfr
- 上一篇:Java 獲取一維數組最小值
- 下一篇:Java 查看生日相關信息
評論
共有 條評論