java.util.Properties的使用

来源:互联网 发布:发票软件怎么使用方法 编辑:程序博客网 时间:2024/04/30 00:59

废话不说,直接见代码:

 

主要功能一:

 

读取配置文件:

a.properties

 

a=234

b=34

 

 

代码:

  1. import java.util.*;   
  2. import java.io.*;   
  3.   
  4. public class LoadSample {   
  5.     public static void main(String args[]) throws Exception {   
  6.       Properties prop = new Properties();   
  7.       FileInputStream fis =    
  8.         new FileInputStream("a.properties");   
  9.       prop.load(fis);   
  10.       prop.list(System.out);   
  11.       System.out.println("/nThe a property: " +   
  12.           prop.getProperty("a"));   
  13.     }   
  14. }  

 

存储配置文件:

  1. import java.util.*;   
  2. import java.io.*;   
  3.   
  4. public class StoreXML {   
  5.     public static void main(String args[]) throws Exception {   
  6.       Properties prop = new Properties();   
  7.       prop.setProperty("one-two""buckle my shoe");   
  8.       prop.setProperty("three-four""shut the door");   
  9.       prop.setProperty("five-six""pick up sticks");   
  10.       prop.setProperty("seven-eight""lay them straight");   
  11.       prop.setProperty("nine-ten""a big, fat hen");   
  12.       FileOutputStream fos =   
  13.         new FileOutputStream("a.properties");   
  14.       prop.store(fos);   
  15.       fos.close();   
  16.     }   
  17. }  

新特性:

支持对特定XML的读取和存储!

想用就卡看api,差不太多,不说了。

 

 

 

 

原创粉丝点击