當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。