本文整理了Java中java.util.Properties.setProperty()
方法的一些代码示例,展示了Properties.setProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.setProperty()
方法的具体详情如下:
包路径:java.util.Properties
类名称:Properties
方法名:setProperty
[英]Maps the specified key to the specified value. If the key already exists, the old value is replaced. The key and value cannot be null.
[中]将指定的键映射到指定的值。如果密钥已存在,则替换旧值。键和值不能为null。
代码示例来源:origin: stanfordnlp/CoreNLP
public static Properties overWriteProperties(Properties bp, Properties ovp) {
for (String propertyName : ovp.stringPropertyNames()) {
bp.setProperty(propertyName,ovp.getProperty(propertyName));
}
return bp;
}
代码示例来源:origin: stanfordnlp/CoreNLP
private static Properties updatePropertiesWithOptions(Properties props, String[] args) {
Properties allProperties = new Properties();
// copy it so props isn't changed but can be overridden by args
for (String key : props.stringPropertyNames()) {
allProperties.setProperty(key, props.getProperty(key));
}
Properties options = StringUtils.argsToProperties(args);
for (String key : options.stringPropertyNames()) {
allProperties.setProperty(key, options.getProperty(key));
}
return allProperties;
}
代码示例来源:origin: dieforfree/qart4j
private static void configLog(String configFile) {
if(new File(configFile).exists()) {
PropertyConfigurator.configure(configFile);
return;
}
Properties properties = new Properties();
properties.setProperty("log4j.rootLogger", "DEBUG, CA");
properties.setProperty("log4j.appender.CA", "org.apache.log4j.ConsoleAppender");
properties.setProperty("log4j.appender.CA.layout", "org.apache.log4j.PatternLayout");
properties.setProperty("log4j.appender.CA.layout.ConversionPattern", "%d{yyyy-MM-dd HH:mm:ss.SSS} %-4r [%t] %-5p %c %x - %m%n");
PropertyConfigurator.configure(properties);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithMultipleProperties() {
String text = "foo=${foo},bar=${bar}";
Properties props = new Properties();
props.setProperty("foo", "bar");
props.setProperty("bar", "baz");
assertEquals("foo=bar,bar=baz", this.helper.replacePlaceholders(text, props));
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testCache1() throws Exception {
Properties cfg = new Properties();
cfg.setProperty(PROP_NODE_ID, grid(0).localNode().id().toString());
Connection conn = null;
try {
conn = DriverManager.getConnection(URL, cfg);
ResultSet rs = conn.createStatement().executeQuery("select _val from Integer order by _val");
int cnt = 0;
while (rs.next())
assertEquals(++cnt, rs.getInt(1));
assertEquals(2, cnt);
}
finally {
if (conn != null)
conn.close();
}
}
代码示例来源:origin: robovm/robovm
/**
* Attempts to establish a connection to the given database URL.
*
* @param url
* a URL string representing the database target to connect with.
* @param user
* a user ID used to login to the database.
* @param password
* a password for the user ID to login to the database.
* @return a {@code Connection} to the database identified by the URL.
* {@code null} if no connection can be established.
* @throws SQLException
* if there is an error while attempting to connect to the
* database identified by the URL.
*/
public static Connection getConnection(String url, String user, String password)
throws SQLException {
Properties theProperties = new Properties();
if (user != null) {
theProperties.setProperty("user", user);
}
if (password != null) {
theProperties.setProperty("password", password);
}
return getConnection(url, theProperties);
}
代码示例来源:origin: apache/incubator-gobblin
private Properties getProperties()
throws IOException {
Properties jobProperties =
GobblinLocalJobLauncherUtils.getJobProperties("runtime_test/writer_output_format_test.properties");
FileUtils.copyFile(new File(GobblinLocalJobLauncherUtils.RESOURCE_DIR + SAMPLE_FILE),
new File(GobblinLocalJobLauncherUtils.RESOURCE_DIR + GobblinLocalJobLauncherUtils.SAMPLE_DIR + SAMPLE_FILE));
jobProperties.setProperty(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL,
GobblinLocalJobLauncherUtils.RESOURCE_DIR + GobblinLocalJobLauncherUtils.SAMPLE_DIR + SAMPLE_FILE);
return jobProperties;
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testSysPropReplace() {
System.getProperties().setProperty("ehcache.match", Number.class.getName());
XmlConfiguration xmlConfig = new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/systemprops.xml"));
assertThat(xmlConfig.getCacheConfigurations().get("bar").getKeyType(), sameInstance((Class)Number.class));
DefaultPersistenceConfiguration persistenceConfiguration = (DefaultPersistenceConfiguration)xmlConfig.getServiceCreationConfigurations().iterator().next();
assertThat(persistenceConfiguration.getRootDirectory(), is(new File(System.getProperty("user.home") + "/ehcache")));
}
代码示例来源:origin: alibaba/nacos
public static void updateTerm(long term) throws Exception {
File file = new File(META_FILE_NAME);
if (!file.exists() && !file.getParentFile().mkdirs() && !file.createNewFile()) {
throw new IllegalStateException("failed to create meta file");
}
try (FileOutputStream outStream = new FileOutputStream(file)) {
// write meta
meta.setProperty("term", String.valueOf(term));
meta.store(outStream, null);
}
}
代码示例来源:origin: neo4j/neo4j
/**
* Stores the data in {@code config} into {@code stream} in a standard java
* {@link Properties} format.
* @param config the data to store in the properties file.
* @param stream the {@link OutputStream} to store the properties in.
* @throws IOException IO error.
*/
public static void store( Map<String, String> config, OutputStream stream ) throws IOException
{
Properties properties = new Properties();
for ( Map.Entry<String, String> property : config.entrySet() )
{
properties.setProperty( property.getKey(), property.getValue() );
}
properties.store( stream, null );
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testRecurseInProperty() {
String text = "foo=${bar}";
Properties props = new Properties();
props.setProperty("bar", "${baz}");
props.setProperty("baz", "bar");
assertEquals("foo=bar", this.helper.replacePlaceholders(text, props));
}
代码示例来源:origin: org.testng/testng
private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {
String relativePath = suite.getName() + File.separatorChar + FILE_NAME;
File suiteFile = new File(config.getOutputDirectory(), relativePath);
Properties attrs = new Properties();
attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);
xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);
return suiteFile;
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testCache1() throws Exception {
Properties cfg = new Properties();
cfg.setProperty(PROP_NODE_ID, grid(0).localNode().id().toString());
Connection conn = null;
try {
conn = DriverManager.getConnection(BASE_URL, cfg);
ResultSet rs = conn.createStatement().executeQuery("select _val from Integer order by _val");
int cnt = 0;
while (rs.next())
assertEquals(++cnt, rs.getInt(1));
assertEquals(2, cnt);
}
finally {
if (conn != null)
conn.close();
}
}
代码示例来源:origin: apache/ignite
/**
* @param allowOverwrite Allow overwriting of existing keys.
* @return Connection to use for the test.
* @throws Exception if failed.
*/
protected Connection createConnection(boolean allowOverwrite) throws Exception {
Properties props = new Properties();
props.setProperty(IgniteJdbcDriver.PROP_STREAMING, "true");
props.setProperty(IgniteJdbcDriver.PROP_STREAMING_FLUSH_FREQ, "500");
if (allowOverwrite)
props.setProperty(IgniteJdbcDriver.PROP_STREAMING_ALLOW_OVERWRITE, "true");
return DriverManager.getConnection(BASE_URL, props);
}
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
@Override
public NacosDataSource getObject() throws Exception {
if (!StringUtils.isEmpty(System.getProperties()
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) {
Properties properties = new Properties();
properties.setProperty(PropertyKeyConst.ACCESS_KEY, this.accessKey);
properties.setProperty(PropertyKeyConst.SERVER_ADDR, this.secretKey);
properties.setProperty(PropertyKeyConst.ENDPOINT, this.endpoint);
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
return new NacosDataSource(properties, groupId, dataId, converter);
}
return new NacosDataSource(serverAddr, groupId, dataId, converter);
}
代码示例来源:origin: apache/incubator-gobblin
private Properties getProperties()
throws IOException {
Properties jobProperties =
GobblinLocalJobLauncherUtils.getJobProperties("runtime_test/task_skip_err_records.properties");
FileUtils.copyFile(new File(GobblinLocalJobLauncherUtils.RESOURCE_DIR + SAMPLE_FILE),
new File(GobblinLocalJobLauncherUtils.RESOURCE_DIR + GobblinLocalJobLauncherUtils.SAMPLE_DIR + SAMPLE_FILE));
jobProperties.setProperty(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL,
GobblinLocalJobLauncherUtils.RESOURCE_DIR + GobblinLocalJobLauncherUtils.SAMPLE_DIR + SAMPLE_FILE);
return jobProperties;
}
}
代码示例来源:origin: stackoverflow.com
FileInputStream in = new FileInputStream("First.properties");
Properties props = new Properties();
props.load(in);
in.close();
FileOutputStream out = new FileOutputStream("First.properties");
props.setProperty("country", "america");
props.store(out, null);
out.close();
代码示例来源:origin: stanfordnlp/CoreNLP
public static Properties noClobberWriteProperties(Properties bp, Properties ovp) {
for (String propertyName : ovp.stringPropertyNames()) {
if (bp.containsKey(propertyName))
continue;
bp.setProperty(propertyName,ovp.getProperty(propertyName));
}
return bp;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testUnresolvedPlaceholderIsIgnored() {
String text = "foo=${foo},bar=${bar}";
Properties props = new Properties();
props.setProperty("foo", "bar");
assertEquals("foo=bar,bar=${bar}", this.helper.replacePlaceholders(text, props));
}
代码示例来源:origin: org.testng/testng
private File referenceSuiteResult(XMLStringBuffer xmlBuffer, String parentDir, ISuiteResult suiteResult) {
Properties attrs = new Properties();
String suiteResultName = suiteResult.getTestContext().getName() + ".xml";
attrs.setProperty(XMLReporterConfig.ATTR_URL, suiteResultName);
xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_TEST, attrs);
return new File(parentDir + File.separatorChar + suiteResultName);
}
内容来源于网络,如有侵权,请联系作者删除!