`
一个人旅行
  • 浏览: 90211 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics