java Properties存取操作例子(无注解)

	public void saveToFile(String newsContent)
	{
		Properties prop = new Properties();
		try
		{
			InputStream is = NewsPush.class.getClassLoader().getResourceAsStream("newspath.properties");
			prop.load(is);
			String newsPath = prop.getProperty("path");
			is.close();
			OutputStream os = new FileOutputStream(newsPath);
			prop.clear();
			prop.setProperty("content", newsContent);
			prop.store(os, "push news content");
			os.close();
		}
		catch(IOException e)
		{
			log.debug("saveToFile error:"+e);
			e.printStackTrace();
		}
	}
	
	public String getSavedContent()
	{
		String content = null;
		Properties prop = new Properties();
		InputStream is = NewsPush.class.getResourceAsStream("/newspath.properties");
		try
		{
			prop.load(is);
			String newsPath = prop.getProperty("path");
			is.close();
			is = new FileInputStream(newsPath);
			prop.load(is);
			content = prop.getProperty("content");
			is.close();
		}
		catch(IOException e)
		{
			log.debug("Get saved content error:"+e);
			e.printStackTrace();
		}
		return content;
	}

你可能感兴趣的:(java)