本文整理匯總了Java中java.util.Properties.load方法的典型用法代碼示例。如果您正苦於以下問題:Java Properties.load方法的具體用法?Java Properties.load怎麽用?Java Properties.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Properties
的用法示例。
在下文中一共展示了Properties.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import java.util.Properties; //導入方法依賴的package包/類
public boolean init() {
props = new Properties();
if (fileName == null)
return false;
try {
InputStream inStream = new FileInputStream(fileName);
props.load(inStream);
/*Iterator iter = props.keySet().iterator();
logger.debug("Properties:");
while (iter.hasNext()) {
String key = (String)iter.next();
logger.debug(key + " -> " + props.get(key));
}*/
return true;
}
catch (IOException e) {
ConvertigoPlugin.logException(e, "Unexpected exception");
throw new RuntimeException("Couldn't read properties");
}
}
示例2: mergeProperties
import java.util.Properties; //導入方法依賴的package包/類
private void mergeProperties(InputStream is,
File confFile,
Collection<String> configMods,
Properties prop)
throws FloodlightModuleException {
try {
Properties fprop = new Properties();
if (is != null) {
fprop.load(is);
} else {
try (FileInputStream fis = new FileInputStream(confFile)) {
fprop.load(fis);
}
}
String moduleList = fprop.getProperty(FLOODLIGHT_MODULES_KEY);
if (moduleList != null) {
moduleList = moduleList.replaceAll("\\s", "");
configMods.addAll(Arrays.asList(moduleList.split(",")));
}
fprop.remove(FLOODLIGHT_MODULES_KEY);
prop.putAll(fprop);
} catch (IOException e) {
throw new FloodlightModuleException(e);
}
}
示例3: calculateConfigs
import java.util.Properties; //導入方法依賴的package包/類
@NonNull
private Map<String,Configuration> calculateConfigs() {
final Map<String,Configuration> cfgs = new HashMap<>();
if (configDir != null) {
for (FileObject kid : configDir.getChildren()) {
if (!kid.hasExt("properties")) { //NOI18N
continue;
}
try {
try (InputStream is = kid.getInputStream()) {
final Properties props = new Properties();
props.load(is);
final String name = kid.getName();
final String label = props.getProperty("$label"); // NOI18N
cfgs.put(name, new Configuration(name, label != null ? label : name));
}
} catch (IOException x) {
LOGGER.log(Level.INFO, null, x);
}
}
}
configs = cfgs;
LOGGER.log(Level.FINEST, "Calculated configurations: {0}", cfgs);
return cfgs;
}
示例4: propertiesFromFile
import java.util.Properties; //導入方法依賴的package包/類
private static Properties propertiesFromFile(String fname)
throws IOException {
FileInputStream fin = new FileInputStream(fname);
try {
Properties p = new Properties();
p.load(fin);
return p;
} finally {
fin.close();
}
}
示例5: loadRelocation
import java.util.Properties; //導入方法依賴的package包/類
@NonNull
private static Properties loadRelocation(
@NonNull final File cacheRoot) {
final Properties result = new Properties();
final File relocationFile = new File (cacheRoot, RELOCATION_FILE);
if (relocationFile.canRead()) {
try {
final FileInputStream in = new FileInputStream(relocationFile);
try {
result.load(in);
} finally {
in.close();
}
} catch (IOException ioe) {
Exceptions.printStackTrace(ioe);
}
}
return result;
}
示例6: loadProperties
import java.util.Properties; //導入方法依賴的package包/類
private Properties loadProperties(String location) {
Properties prop = new Properties();
if (new File(location).exists()) {
try (FileInputStream inputStream = new FileInputStream(location)) {
prop.load(inputStream);
} catch (IOException ex) {
Logger.getLogger(SeleniumServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
return prop;
}
示例7: setOsNameAndVersion
import java.util.Properties; //導入方法依賴的package包/類
/**
* Sets the OS name and version from environment information.
*/
protected void setOsNameAndVersion(){
super.setOsNameAndVersion();
if (osName.equals("SunOS")) {
//don't care os name on Solaris
osName = null;
} else if (osName.equals("Linux")) {
try {
File f;
if ((f = new File("/etc/fedora-release")).canRead()) {
osName = "Fedora";
osVersion = getVersionString(f);
} else if ((f = new File("/etc/redhat-release")).canRead()) {
osName = "RedHat";
osVersion = getVersionString(f);
} else if ((f = new File("/etc/turbolinux-release")).canRead()) {
osName = "Turbo";
osVersion = getVersionString(f);
} else if ((f = new File("/etc/SuSE-release")).canRead()) {
osName = "SuSE";
osVersion = getVersionString(f);
} else if ((f = new File("/etc/lsb-release")).canRead()) {
/* Ubuntu and (perhaps others) use only lsb-release.
* Syntax and encoding is compatible with java properties.
* For Ubuntu the ID is "Ubuntu".
*/
Properties props = new Properties();
props.load(new FileInputStream(f));
osName = props.getProperty("DISTRIB_ID");
osVersion = props.getProperty("DISTRIB_RELEASE");
}
} catch (Exception e) {
}
}
return;
}
示例8: parseProperties
import java.util.Properties; //導入方法依賴的package包/類
public static Properties parseProperties(String propertyString) {
Properties properties = new Properties();
try {
Reader propertyReader = new StringReader(propertyString.replaceAll(";", "\n"));
properties.load(propertyReader);
} catch (IOException e) {
// Can't happen with StringReader
}
return properties;
}
示例9: getSecondaryServicePrincipalClientID
import java.util.Properties; //導入方法依賴的package包/類
/**
* Retrieve the secondary service principal client ID.
* @param envSecondaryServicePrincipal an Azure Container Registry
* @return a service principal client ID
* @throws Exception exception
*/
public static String getSecondaryServicePrincipalClientID(String envSecondaryServicePrincipal) throws Exception {
Properties authSettings = new Properties();
FileInputStream credentialsFileStream = new FileInputStream(new File(envSecondaryServicePrincipal));
authSettings.load(credentialsFileStream);
credentialsFileStream.close();
return authSettings.getProperty("client");
}
示例10: configLog4j
import java.util.Properties; //導入方法依賴的package包/類
private static void configLog4j() {
InputStream inStreamLog4j = DiameterServer.class.getClassLoader().getResourceAsStream("log4j.properties");
Properties propertiesLog4j = new Properties();
try {
propertiesLog4j.load(inStreamLog4j);
PropertyConfigurator.configure(propertiesLog4j);
} catch (Exception e) {
e.printStackTrace();
}
log.debug("log4j configured");
}
示例11: getVersion
import java.util.Properties; //導入方法依賴的package包/類
public String[] getVersion() throws Exception {
URL url = getClass().getResource("/version.txt");
if (url == null) {
return new String[] {"No version.txt file found in the classpath. Is examples.jar in the classpath?"};
}
Properties properties = new Properties();
properties.load(url.openStream());
return new String[] {
properties.getProperty("Application-name") + " version \"" + properties.getProperty("Version") + "\"",
"Built: " + properties.getProperty("Buildtime"),
};
}
示例12: readProperties
import java.util.Properties; //導入方法依賴的package包/類
public AgroalPropertiesReader readProperties(File file) throws IOException {
try ( InputStream inputStream = new FileInputStream( file ) ) {
Properties properties = new Properties();
properties.load( inputStream );
return readProperties( properties );
}
}
示例13: loadProperties
import java.util.Properties; //導入方法依賴的package包/類
private static void loadProperties(File propertiesFile, Properties properties) throws IOException {
InputStream inStream = new FileInputStream(propertiesFile);
try {
properties.load(inStream);
} finally {
inStream.close();
}
}
示例14: getSchemaExport
import java.util.Properties; //導入方法依賴的package包/類
private SchemaExport getSchemaExport(Configuration cfg) throws HibernateException, IOException {
Properties properties = new Properties();
properties.putAll( cfg.getProperties() );
if (propertiesFile == null) {
properties.putAll( getProject().getProperties() );
}
else {
properties.load( new FileInputStream(propertiesFile) );
}
cfg.setProperties(properties);
return new SchemaExport(cfg)
.setHaltOnError(haltOnError)
.setOutputFile( outputFile.getPath() )
.setDelimiter(delimiter);
}
示例15: ConfigItem
import java.util.Properties; //導入方法依賴的package包/類
/**
* 取默認的配置文件
*/
ConfigItem(String file) {
try (InputStream is = ConfigUtil.class.getResourceAsStream(file)) {
Properties p = new Properties();
p.load(is);
this.pro = p;
} catch (IOException e) {
throw new ZhhrException("加載配置信息出錯:" + e.getMessage());
}
}