本文整理了Java中java.util.Properties.store()
方法的一些代码示例,展示了Properties.store()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.store()
方法的具体详情如下:
包路径:java.util.Properties
类名称:Properties
方法名:store
[英]Stores properties to the specified OutputStream, using ISO-8859-1. See "Character Encoding".
[中]使用ISO-8859-1将属性存储到指定的输出流。请参阅“{$0$}”。
代码示例来源:origin: apache/flink
private static void writeYarnProperties(Properties properties, File propertiesFile) {
try (final OutputStream out = new FileOutputStream(propertiesFile)) {
properties.store(out, "Generated YARN properties file");
} catch (IOException e) {
throw new RuntimeException("Error writing the properties file", e);
}
propertiesFile.setReadable(true, false); // readable for all.
}
代码示例来源:origin: neo4j/neo4j
/**
* Stores the data in {@code config} into {@code writer} in a standard java
* {@link Properties} format.
*
* @param config the data to store in the properties file.
* @param writer the {@link Writer} to store the properties in.
* @throws IOException IO error.
*/
public static void store( Map<String, String> config, Writer writer ) throws IOException
{
Properties properties = new Properties();
properties.putAll( config );
properties.store( writer, null );
}
代码示例来源: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: fabric8io/docker-maven-plugin
private void writeProperties(Properties props, String file) throws IOException {
File propFile = new File(file);
try (OutputStream os = new FileOutputStream(propFile)) {
props.store(os, "Docker ports");
} catch (IOException e) {
throw new IOException("Cannot write properties to " + file + ": " + e, e);
}
}
}
代码示例来源:origin: Tencent/tinker
public void gen() throws Exception {
addTinkerID();
Properties newProperties = new Properties();
for (String key : config.mPackageFields.keySet()) {
newProperties.put(key, config.mPackageFields.get(key));
}
String comment = "base package config field";
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(packageInfoFile, false));
newProperties.store(os, comment);
} finally {
StreamUtil.closeQuietly(os);
}
}
}
代码示例来源:origin: jersey/jersey
private static void storeSettings() {
FileOutputStream st = null;
try {
st = new FileOutputStream(PROPERTIES_FILE_NAME);
PROPERTIES.store(st, null);
} catch (final IOException e) {
// ignore
} finally {
try {
if (st != null) {
st.close();
}
} catch (final IOException ex) {
// ignore
}
}
}
代码示例来源:origin: stackoverflow.com
Properties props = new Properties() {
@Override
public Set<Object> keySet(){
return Collections.unmodifiableSet(new TreeSet<Object>(super.keySet()));
}
@Override
public synchronized Enumeration<Object> keys() {
return Collections.enumeration(new TreeSet<Object>(super.keySet()));
}
};
props.put("B", "Should come second");
props.put("A", "Should come first");
props.storeToXML(new FileOutputStream(new File("sortedProps.xml")), null);
props.store(new FileOutputStream(new File("sortedProps.properties")), 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: apache/hbase
@Test
public void testNoManifest() throws Exception {
File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
TestJarFinder.class.getName() + "-testNoManifest");
delete(dir);
dir.mkdirs();
File propsFile = new File(dir, "props.properties");
Writer writer = new FileWriter(propsFile);
new Properties().store(writer, "");
writer.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream zos = new JarOutputStream(baos);
JarFinder.jarDir(dir, "", zos);
JarInputStream jis =
new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
Assert.assertNotNull(jis.getManifest());
jis.close();
}
}
代码示例来源:origin: kaaproject/kaa
byte[] defaultConfigurationData) throws IOException {
Properties clientProperties = new Properties();
clientProperties.load(clientPropertiesStream);
clientProperties.store(baos, "");
代码示例来源:origin: caoxinyu/RedisClient
public static void write(String propertyFile, String key, String value) throws IOException {
Properties props = getProperty(propertyFile);
OutputStream fos = new FileOutputStream(propertyFile);
props.setProperty(key, value);
props.store(fos, "Update '" + key + "' value");
}
代码示例来源:origin: apache/cloudstack
@Override
public synchronized void persist(String key, String value) {
if (!loadFromFile(_file)) {
s_logger.error("Failed to load changes and then write to them");
}
_properties.setProperty(key, value);
FileOutputStream output = null;
try {
output = new FileOutputStream(_file);
_properties.store(output, _name);
output.flush();
output.close();
} catch (IOException e) {
s_logger.error("Uh-oh: ", e);
} finally {
IOUtils.closeQuietly(output);
}
}
代码示例来源:origin: EngineHub/WorldEdit
@Override
public void load() {
try (InputStream stream = new FileInputStream(path)) {
properties.load(stream);
} catch (FileNotFoundException ignored) {
} catch (IOException e) {
try (OutputStream output = new FileOutputStream(path)) {
properties.store(output, "Don't put comments; they get removed");
} catch (IOException e) {
log.log(Level.WARNING, "Failed to write configuration", e);
代码示例来源:origin: gocd/gocd
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setHeader("Plugins-Status", status);
pluginProps.setProperty("Active Mock Bundle 1", "1.1.1");
pluginProps.setProperty("Active Mock Bundle 2", "2.2.2");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pluginProps.store(baos, "Go Plugins for Testing");
resp.getOutputStream().write(baos.toByteArray());
baos.close();
}
}
代码示例来源: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: apache/incubator-dubbo
File lockfile = new File(file.getAbsolutePath() + ".lock");
if (!lockfile.exists()) {
lockfile.createNewFile();
file.createNewFile();
try (FileOutputStream outputFile = new FileOutputStream(file)) {
properties.store(outputFile, "Dubbo Registry Cache");
代码示例来源:origin: stackoverflow.com
Map<String, String> ldapContent = new HashMap<String, String>();
Properties properties = new Properties();
for (Map.Entry<String,String> entry : ldapContent.entrySet()) {
properties.put(entry.getKey(), entry.getValue());
}
properties.store(new FileOutputStream("data.properties"), null);
代码示例来源:origin: stagemonitor/stagemonitor
@Override
public void save(String key, String value) throws IOException {
if (file != null) {
synchronized (this) {
properties.put(key, value);
final FileOutputStream out = new FileOutputStream(file);
properties.store(out, null);
out.flush();
out.close();
}
} else {
throw new IOException(location + " is not writeable");
}
}
代码示例来源:origin: ethereum/ethereumj
public void putDatabaseVersion(SystemProperties config, Integer version) {
final File versionFile = getDatabaseVersionFile(config);
versionFile.getParentFile().mkdirs();
try (Writer writer = new FileWriter(versionFile)) {
Properties prop = new Properties();
prop.setProperty("databaseVersion", version.toString());
prop.store(writer, "Generated database version");
} catch (Exception e) {
throw new Error("Problem writing current database version ", e);
}
}
代码示例来源:origin: Netflix/Priam
private void writeCassandraSnitchProperties() {
final NodeType nodeType = dseConfig.getNodeType();
if (nodeType == NodeType.REAL_TIME_QUERY) return;
Reader reader = null;
try {
String filePath = config.getCassHome() + "/conf/" + RACKDC_PROPERTY_FILENAME;
reader = new FileReader(filePath);
Properties properties = new Properties();
properties.load(reader);
String suffix = "";
if (nodeType == NodeType.SEARCH) suffix = "_solr";
if (nodeType == NodeType.ANALYTIC_HADOOP) suffix = "_hadoop";
if (nodeType == NodeType.ANALYTIC_HADOOP_SPARK) suffix = "_hadoop_spark";
if (nodeType == NodeType.ANALYTIC_SPARK) suffix = "_spark";
properties.put("dc_suffix", suffix);
properties.store(new FileWriter(filePath), "");
} catch (Exception e) {
throw new RuntimeException("Unable to read " + RACKDC_PROPERTY_FILENAME, e);
} finally {
FileUtils.closeQuietly(reader);
}
}
内容来源于网络,如有侵权,请联系作者删除!