当前位置: 首页>>代码示例>>Java>>正文


Java Properties.store方法代码示例

本文整理汇总了Java中java.util.Properties.store方法的典型用法代码示例。如果您正苦于以下问题:Java Properties.store方法的具体用法?Java Properties.store怎么用?Java Properties.store使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Properties的用法示例。


在下文中一共展示了Properties.store方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import java.util.Properties; //导入方法依赖的package包/类
/**
 * 保存修改
 * @throws FileNotFoundException
 * @throws IOException
 */
public void save() throws FileNotFoundException, IOException {
	Properties prop = new Properties();
	if(fileName==null){
		throw new FileNotFoundException("Unspecified file name.");
	}
	FileOutputStream fos = new FileOutputStream(fileName);
	//遍历HashMap
	Iterator<Entry<String, String>> iter = hashMap.entrySet().iterator();
	while (iter.hasNext()) {
		Entry<String, String> entry = iter.next();
		prop.setProperty(entry.getKey(), entry.getValue());
	}
	//写入文件
	prop.store(fos, null);
	fos.close();
}
 
开发者ID:landriesnidis,项目名称:PCloud_Server_v3,代码行数:22,代码来源:PropertiesHelper.java

示例2: store

import java.util.Properties; //导入方法依赖的package包/类
@Override
public void store(String cacheEntryName, InputStream inputStream, long expirationDate) {
    createCache();

    OutputStream xmlOut = null;
    OutputStream metaOut = null;
    try {
        File xmlFile = getXmlFile(cacheEntryName);
        xmlOut = new FileOutputStream(xmlFile);
        IOUtils.copy(inputStream, xmlOut);

        File metaFile = getMetaFile(cacheEntryName);
        Properties properties = new Properties();

        // Note: Ignore the given expirationDate, since Last.fm sets it to just one day ahead.
        properties.setProperty("expiration-date", Long.toString(getExpirationDate()));

        metaOut = new FileOutputStream(metaFile);
        properties.store(metaOut, null);
    } catch (Exception e) {
        // we ignore the exception. if something went wrong we just don't cache it.
    } finally {
        IOUtils.closeQuietly(xmlOut);
        IOUtils.closeQuietly(metaOut);
    }
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:27,代码来源:LastFmCache.java

示例3: fetchNextPeriod

import java.util.Properties; //导入方法依赖的package包/类
@Override
public Boolean fetchNextPeriod(String prefixName) {
	Properties props = new Properties();
	try {
		props.load(new FileInputStream(filePath));
		String minStr = props.getProperty(prefixName + KEY_MIN_NAME);
		String maxStr = props.getProperty(prefixName + KEY_MAX_NAME);
		String hisIDS = props.getProperty(prefixName + KEY_HIS_NAME);
		props.setProperty(prefixName + KEY_HIS_NAME,
				"".equals(hisIDS) ? minStr + "-" + maxStr : "," + minStr
						+ "-" + maxStr);
		long minId = Long.parseLong(minStr);
		long maxId = Long.parseLong(maxStr);
		props.setProperty(prefixName + KEY_MIN_NAME, (maxId + 1) + "");
		props.setProperty(prefixName + KEY_MAX_NAME,
				(maxId - minId + maxId + 1) + "");
		props.setProperty(prefixName + KEY_CUR_NAME, maxStr);
		OutputStream fos = new FileOutputStream(filePath);
		props.store(fos, "");
	} catch (Exception e) {
		logger.error(e.getLocalizedMessage());
		return false;
	}
	return true;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:26,代码来源:IncrSequencePropHandler.java

示例4: saveHexid

import java.util.Properties; //导入方法依赖的package包/类
/**
 * Save hexadecimal ID of the server in the L2Properties file.
 * @param serverId the ID of the server whose hexId to save
 * @param hexId the hexadecimal ID to store
 * @param fileName name of the L2Properties file
 */
public static void saveHexid(int serverId, String hexId, String fileName)
{
	try
	{
		final Properties hexSetting = new Properties();
		final File file = new File(fileName);
		// Create a new empty file only if it doesn't exist
		file.createNewFile();
		try (OutputStream out = new FileOutputStream(file))
		{
			hexSetting.setProperty("ServerID", String.valueOf(serverId));
			hexSetting.setProperty("HexID", hexId);
			hexSetting.store(out, "The HexId to Auth into LoginServer");
		}
	}
	catch (Exception e)
	{
		LOGGER.warning(StringUtil.concat("Failed to save hex id to ", fileName, " File."));
		LOGGER.warning("Config: " + e.getMessage());
	}
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:28,代码来源:Config.java

示例5: save

import java.util.Properties; //导入方法依赖的package包/类
public static void save() {
	try (FileOutputStream fis = new FileOutputStream(configFile)) {
		Properties p = new Properties();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < Data.recentScripts.size(); i++) {
			String name = (String) Data.recentScripts.get(i);
			sb.append(name);
			sb.append(":::");
		}
		p.setProperty("recent_scripts", sb.toString());
		p.setProperty("default_script", "script.py");
		p.setProperty("RAM_xmx", Data.xmxValue);
		p.setProperty("force_use_GPU", Data.forceUseGPU ? "1" : "0");
		p.setProperty("use_fragments_cache",
				Data.useInternalCache == true ? "1" : "0");
		p.store(new FileOutputStream(configFile), null);
	} catch (IOException e1) {
		e1.printStackTrace();
	}
}
 
开发者ID:1Ridav,项目名称:PengueeBot,代码行数:21,代码来源:MyProperties.java

示例6: testLoggerReconfiguration

import java.util.Properties; //导入方法依赖的package包/类
@Test
public void testLoggerReconfiguration() throws Exception {
  setLogLevel(logger, Level.ERROR);

  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("error", (s, aLong) -> aLong + 1);

  Properties properties = new Properties();
  properties.setProperty("name", "PropertiesConfig");
  properties.setProperty("appenders", "console");
  properties.setProperty("appender.console.type", "Console");
  properties.setProperty("appender.console.name", "STDOUT");
  properties.setProperty("rootLogger.level", "debug");
  properties.setProperty("rootLogger.appenderRefs", "stdout");
  properties.setProperty("rootLogger.appenderRefs", "stdout");
  properties.setProperty("rootLogger.appenderRef.stdout.ref", "STDOUT");
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  properties.store(baos, null);
  ConfigurationSource source = new ConfigurationSource(
      new ByteArrayInputStream(baos.toByteArray()));

  PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
  LoggerContext context = (LoggerContext) LogManager.getContext(false);
  PropertiesConfiguration configuration = factory.getConfiguration(context, source);
  configuration.start();
  context.updateLoggers(configuration);

  logger.error("error!");
  assertEquals(expectedCounts, getCurrentCounts());

}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:33,代码来源:Log4J2InstrumentationTest.java

示例7: updateConfigurationWith

import java.util.Properties; //导入方法依赖的package包/类
static void updateConfigurationWith(Properties propertyFile, boolean append) {
    try {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        propertyFile.store(bytes, propertyFile.getProperty("test.name"));
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes.toByteArray());
        Function<String, BiFunction<String,String,String>> remapper =
                append ? (x) -> ((o, n) -> n == null ? o : n)
                       : (x) -> ((o, n) -> n);
        LogManager.getLogManager().updateConfiguration(bais, remapper);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:HandlersOnComplexUpdate.java

示例8: putDatabaseVersion

import java.util.Properties; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:12,代码来源:Initializer.java

示例9: saveConfigNoDirs

import java.util.Properties; //导入方法依赖的package包/类
/**
 * 保存文件到/data/data/package_name/files下 无法指定位置
 * 
 * @param fileName
 * @param properties 设定文件
 */
public static void saveConfigNoDirs(String fileName, Properties properties)
{
    try
    {
        FileOutputStream s = GlobalState.getInstance().openFileOutput(fileName, Context.MODE_PRIVATE);
        properties.store(s, "");
    }
    catch (Exception e)
    {
        LogUtil.e(e);
    }
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:19,代码来源:MIP_Properties.java

示例10: storeActiveLicenseProperties

import java.util.Properties; //导入方法依赖的package包/类
/**
 * Store active license properties. Requires RapidMiner to be running ad standalone GUI
 * application.
 */
public static void storeActiveLicenseProperties(License activeLicense) {
	// do nothing when RapidMiner is not executed as standalone GUI application
	if (RapidMiner.getExecutionMode() != ExecutionMode.UI) {
		return;
	}

	// load existing properties file
	File licensePropertiesFile = FileSystemService.getUserConfigFile(LICENSE_PROPERTIES_PATH);
	Properties licenseProperties = LicenseTools.loadLastActiveLicenseProperties();

	// store properties necessary to identify the license
	licenseProperties.setProperty(LAST_ACTIVE_LICENSE_PRODUCT_ID, activeLicense.getProductId());
	licenseProperties.setProperty(LAST_ACTIVE_LICENSE_PRODUCT_EDITION, activeLicense.getProductEdition());
	licenseProperties.setProperty(LAST_ACTIVE_LICENSE_PRECEDENCE, String.valueOf(activeLicense.getPrecedence()));
	if (activeLicense.getExpirationDate() != null) {
		String dateString = ISO_DATE_FORMATTER.get().format(activeLicense.getExpirationDate());
		licenseProperties.setProperty(LAST_ACTIVE_LICENSE_EXPIRATION_DATE, dateString);
	}

	// store properties
	try (FileOutputStream out = new FileOutputStream(licensePropertiesFile)) {
		licenseProperties.store(out, "RapidMiner Studio License Properties");
	} catch (IOException e) {
		LogService.getRoot().log(Level.WARNING,
				"com.rapidminer.gui.license.RMLicenseManagerListener.storing_properties_failed", e);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:32,代码来源:LicenseTools.java

示例11: service

import java.util.Properties; //导入方法依赖的package包/类
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
	final String path = req.getPathInfo();

	if( path.equals("/refresh") )
	{
		languageService.refreshBundles();

		resp.setContentType("text/plain");
		ServletOutputStream out = resp.getOutputStream();
		out.print("Bundles refreshed");
		out.close();
		return;
	}

	Matcher m = Pattern.compile("^/([a-zA-Z_]*)/([a-zA-Z-]+)\\.properties$").matcher(path);
	if( !m.matches() || m.groupCount() != 2 )
	{

		throw new ServletException("Bundle Group name is invalid: " + path);
	}

	final ResourceBundle resourceBundle = languageService.getResourceBundle(LocaleUtils.parseLocale(m.group(1)),
		m.group(2));

	final Properties text = new Properties();
	for( String key : resourceBundle.keySet() )
	{
		text.put(key, resourceBundle.getString(key));
	}

	resp.setContentType("text/plain");
	resp.setHeader("Content-Disposition", "inline; filename=" + path + ".properties");

	text.store(resp.getOutputStream(), null);
}
 
开发者ID:equella,项目名称:Equella,代码行数:38,代码来源:LanguageServlet.java

示例12: saveProperties

import java.util.Properties; //导入方法依赖的package包/类
public static void saveProperties(Properties props, String name,
                                      OutputStream os) throws IOException {

//#ifdef JAVA2FULL
        props.store(os, name);

//#else
/*
        props.save(os, name);
*/

//#endif
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:14,代码来源:JavaSystem.java

示例13: before

import java.util.Properties; //导入方法依赖的package包/类
@Before
public void before() throws IOException {
  clusterProperties = new File(temp.getRoot(), "cluster.properties");
  Properties properties = new Properties();
  properties.put("graphite.host", "my.graphite.host:2003");
  properties.put("graphite.prefix", "chandler");
  try (OutputStream outputStream = new FileOutputStream(clusterProperties)) {
    properties.store(outputStream, null);
  }

  validator = new GraphiteValidator(conf);
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:13,代码来源:GraphiteValidatorIntegrationTest.java

示例14: updateConfigurationWith

import java.util.Properties; //导入方法依赖的package包/类
static void updateConfigurationWith(Properties propertyFile,
        Function<String,BiFunction<String,String,String>> remapper) {
    try {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        propertyFile.store(bytes, propertyFile.getProperty("test.name"));
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes.toByteArray());
        LogManager.getLogManager().updateConfiguration(bais, remapper);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:SimpleUpdateConfigurationTest.java

示例15: saveProperties

import java.util.Properties; //导入方法依赖的package包/类
@Override
public void saveProperties(
        @NonNull File file,
        @NonNull Properties props,
        @NonNull String comments) throws IOException {
    Closer closer = Closer.create();
    try {
        OutputStream fos = closer.register(newFileOutputStream(file));
        props.store(fos, comments);
    } catch (Throwable e) {
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:FileOp.java


注:本文中的java.util.Properties.store方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。