- 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 Properties存取操作例子(无注释)
最新推荐文章于 2024-07-30 10:57:38 发布