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

Java代码 
  1. public void saveToFile(String newsContent)  
  2. {  
  3.     Properties prop = new Properties();  
  4.     try  
  5.     {  
  6.         InputStream is = NewsPush.class.getClassLoader().getResourceAsStream("newspath.properties");  
  7.         prop.load(is);  
  8.         String newsPath = prop.getProperty("path");  
  9.         is.close();  
  10.         OutputStream os = new FileOutputStream(newsPath);  
  11.         prop.clear();  
  12.         prop.setProperty("content", newsContent);  
  13.         prop.store(os, "push news content");  
  14.         os.close();  
  15.     }  
  16.     catch(IOException e)  
  17.     {  
  18.         log.debug("saveToFile error:"+e);  
  19.         e.printStackTrace();  
  20.     }  
  21. }  
  22.   
  23. public String getSavedContent()  
  24. {  
  25.     String content = null;  
  26.     Properties prop = new Properties();  
  27.     InputStream is = NewsPush.class.getResourceAsStream("/newspath.properties");  
  28.     try  
  29.     {  
  30.         prop.load(is);  
  31.         String newsPath = prop.getProperty("path");  
  32.         is.close();  
  33.         is = new FileInputStream(newsPath);  
  34.         prop.load(is);  
  35.         content = prop.getProperty("content");  
  36.         is.close();  
  37.     }  
  38.     catch(IOException e)  
  39.     {  
  40.         log.debug("Get saved content error:"+e);  
  41.         e.printStackTrace();  
  42.     }  
  43.     return content;  
  44. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值