本文整理匯總了Java中org.apache.commons.configuration.PropertiesConfiguration.save方法的典型用法代碼示例。如果您正苦於以下問題:Java PropertiesConfiguration.save方法的具體用法?Java PropertiesConfiguration.save怎麽用?Java PropertiesConfiguration.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.configuration.PropertiesConfiguration
的用法示例。
在下文中一共展示了PropertiesConfiguration.save方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveRecord
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
public void saveRecord() throws Exception {
if (file.exists()) {
// file.renameTo(new File(Configs.recordFileName+".bak"));
file.delete();
}
file.createNewFile();
PropertiesConfiguration record = new PropertiesConfiguration(
Configs.recordFileName);
record.addProperty("verifiedUsers", Records.verifiedUsers.toArray());
// record.addProperty("records", Records.records);
Object[] usrEntries = Records.records.keySet().toArray();
record.addProperty("usrEntries", usrEntries);
for (Object usr : usrEntries) {
record.addProperty((String) usr, Records.records.get(usr).toArray());
}
record.save();
}
示例2: createDefault
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
public void createDefault() throws Exception {
if (file.exists()) {
file.renameTo(new File(Enterence.propFileName + ".bak"));
}
file.createNewFile();
PropertiesConfiguration config = new PropertiesConfiguration(
Enterence.propFileName);
config.setProperty("sudoers", Configs.sudoers);
config.setProperty("sudoPwd", Configs.sudoPwd);
config.setProperty("server", Configs.server);
config.setProperty("name", Configs.name);
config.setProperty("pwd", Configs.pwd);
config.setProperty("channels", Configs.channels);
config.setProperty("preffix", Configs.preffix);
config.setProperty("sudoers", Configs.sudoers);
config.setProperty("recordFileName", Configs.recordFileName);
config.setProperty("useProxy", Configs.useProxy);
config.setProperty("Proxy", Configs.Proxy);
config.save();
}
示例3: normalizeCommands
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
/**
* Normalize all guild commands
* @param collection All commands
* @throws ConfigurationException If apache config throws an exception
*/
private static void normalizeCommands(Collection<Command> collection) throws ConfigurationException {
Collection<File> found = FileUtils.listFiles(new File("resources/guilds"),
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
found.add(new File("resources/guilds/template.properties"));
for (File f : found) {
if (f.getName().equals("GuildProperties.properties") || f.getName().equals("template.properties")) {
PropertiesConfiguration config = new PropertiesConfiguration(f);
List<String> enabledCommands = config.getList("EnabledCommands").stream()
.map(object -> Objects.toString(object, null))
.collect(Collectors.toList());
List<String> disabledCommands = config.getList("DisabledCommands").stream()
.map(object -> Objects.toString(object, null))
.collect(Collectors.toList());
for (Command c : collection) {
if (!enabledCommands.contains(c.toString()) && !disabledCommands.contains(c.toString())) {
enabledCommands.add(c.toString());
}
}
config.setProperty("EnabledCommands", enabledCommands);
config.save();
}
}
}
示例4: currentConfig
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
@Override
public synchronized String currentConfig() {
PropertiesConfiguration saver = new PropertiesConfiguration();
StringWriter writer = new StringWriter();
saver.copy(config);
try { saver.save(writer); }
catch (Exception e) {
throw new MetricsConfigException("Error stringify config", e);
}
return writer.toString();
}
示例5: toString
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
static String toString(Configuration c) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
PrintStream ps = new PrintStream(buffer, false, "UTF-8");
PropertiesConfiguration tmp = new PropertiesConfiguration();
tmp.copy(c);
tmp.save(ps);
return buffer.toString("UTF-8");
} catch (Exception e) {
throw new MetricsConfigException(e);
}
}
示例6: dump
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
static void dump(String header, Configuration c, PrintStream out) {
PropertiesConfiguration p = new PropertiesConfiguration();
p.copy(c);
if (header != null) {
out.println(header);
}
try { p.save(out); }
catch (Exception e) {
throw new RuntimeException("Error saving config", e);
}
}
示例7: save
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
public String save() {
// 設定文件初期讀入
try {
PropertiesConfiguration languageConf = new PropertiesConfiguration(Thread.currentThread()
.getContextClassLoader().getResource("language/package.properties"));
languageConf.setProperty(YiDuConfig.TITLE, Utils.escapePropterties(title));
languageConf.setProperty(YiDuConfig.SITEKEYWORDS, Utils.escapePropterties(siteKeywords));
languageConf.setProperty(YiDuConfig.SITEDESCRIPTION, Utils.escapePropterties(siteDescription));
languageConf.setProperty(YiDuConfig.NAME, Utils.escapePropterties(name));
languageConf.setProperty(YiDuConfig.URL, Utils.escapePropterties(url));
languageConf.setProperty(YiDuConfig.COPYRIGHT, Utils.escapePropterties(copyright));
languageConf.setProperty(YiDuConfig.BEIANNO, Utils.escapePropterties(beianNo));
languageConf.setProperty(YiDuConfig.ANALYTICSCODE, Utils.escapePropterties(analyticscode));
languageConf.setProperty(YiDuConfig.CATEGORY, Utils.escapePropterties(category));
File languageFile = new File(languageConf.getPath());
OutputStream out = new FileOutputStream(languageFile);
languageConf.save(out);
} catch (Exception e) {
addActionError(e.getMessage());
logger.error(e);
return ADMIN_ERROR;
}
loadData();
addActionMessage(getText("messages.save.success"));
return INPUT;
}
示例8: createDefault
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
public void createDefault() throws Exception {
if (file.exists()) {
// file.renameTo(new File(Configs.recordFileName+".bak"));
file.delete();
}
file.createNewFile();
PropertiesConfiguration record = new PropertiesConfiguration(
Configs.recordFileName);
Records.mutedUsers.add("foo_-_");
Records.records.put("foo_-_", new HashSet<String>() {
{
this.add("test");
}
});
Records.verifiedUsers.add("d0048");
record.addProperty("verifiedUsers", Records.verifiedUsers.toArray());
// record.addProperty("records", Records.records);
Object[] usrEntries = Records.records.keySet().toArray();
record.addProperty("usrEntries", usrEntries);
for (Object usr : usrEntries) {
record.addProperty((String) usr, Records.records.get(usr).toArray());
}
record.save();
}
示例9: setUserValues
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
private void setUserValues(String propName, String propValue){
try {
PropertiesConfiguration config = new PropertiesConfiguration(extFolder+propFileName);
config.setProperty(propName, propValue);
config.save();
//logger.info(config.getPath());
} catch (Exception e) {
logger(logger,"error", e.getMessage());
}
}
示例10: loadData
import org.apache.commons.configuration.PropertiesConfiguration; //導入方法依賴的package包/類
@Override
protected void loadData() {
if (StringUtils.isEmpty(uv)) {
addActionError(getText("errors.not.exsits.upgradeVersion"));
return;
}
// step1下載安裝包並解壓縮
logger.info("going to download upgrade file : " + uv + ".zip");
ZIP_FILE_URL = SITE_URL + uv + ".zip";
String currentPath = UpgradeAction.class.getClassLoader().getResource("").getPath();
File f = new File(currentPath).getParentFile().getParentFile();
INPUT_ZIP_FILE = f.getAbsolutePath() + File.separator + "tmp" + File.separator + uv + ".zip";
OUTPUT_FOLDER = f.getAbsolutePath() + File.separator + "tmp" + File.separator + uv + File.separator;
BASE_FOLDER = f.getAbsolutePath() + File.separator;
downloadFile();
if (this.hasErrors()) {
return;
}
logger.info("going to unzip upgrade file : " + uv + ".zip");
unZipFile();
if (this.hasErrors()) {
return;
}
// 讀取rules文件
String content = readFileByLines(OUTPUT_FOLDER + "rule");
Gson g = new Gson();
List<UpgradeBean> upgradeList = g.fromJson(content, new TypeToken<List<UpgradeBean>>() {
}.getType());
for (UpgradeBean rb : upgradeList) {
switch (rb.getType()) {
case FileType.STATIC:
case FileType.CLASS:
case FileType.FTL:
case FileType.JSP:
case FileType.XML:
// 替換或添加靜態文件,class文件,ftl,jsp
// 直接覆蓋
File srcFile = new File(OUTPUT_FOLDER + rb.getPath());
File destFile = new File(BASE_FOLDER + rb.getPath());
try {
FileUtils.copyFile(srcFile, destFile);
} catch (IOException e1) {
// TODO Auto-generated catch block
logger.error(e1.getMessage(), e1);
addActionError(e1.getMessage());
return;
}
break;
case FileType.PROPERTIES:
// 修改properties文件
try {
PropertiesConfiguration propertiesFile = new PropertiesConfiguration(Thread.currentThread().getContextClassLoader()
.getResource(rb.getFileName()));
propertiesFile.setProperty(rb.getKey(), rb.getContent());
File jdbcFile = new File(propertiesFile.getPath());
OutputStream out = new FileOutputStream(jdbcFile);
propertiesFile.save(out);
} catch (Exception e) {
addActionError(e.getMessage());
logger.error(e);
}
break;
case FileType.SQL:
// 執行文件
upgradeService.excuteUpgradeSql(rb.getSql());
break;
default:
break;
}
}
}