废话不说,直接见代码:
主要功能一:
读取配置文件:
(
a.properties
a=234
b=34
)
代码:
- import java.util.*;
- import java.io.*;
- public class LoadSample {
- public static void main(String args[]) throws Exception {
- Properties prop = new Properties();
- FileInputStream fis =
- new FileInputStream("a.properties");
- prop.load(fis);
- prop.list(System.out);
- System.out.println("/nThe a property: " +
- prop.getProperty("a"));
- }
- }
存储配置文件:
- import java.util.*;
- import java.io.*;
- public class StoreXML {
- public static void main(String args[]) throws Exception {
- Properties prop = new Properties();
- prop.setProperty("one-two", "buckle my shoe");
- prop.setProperty("three-four", "shut the door");
- prop.setProperty("five-six", "pick up sticks");
- prop.setProperty("seven-eight", "lay them straight");
- prop.setProperty("nine-ten", "a big, fat hen");
- FileOutputStream fos =
- new FileOutputStream("a.properties");
- prop.store(fos);
- fos.close();
- }
- }
新特性:
支持对特定XML的读取和存储!
想用就卡看api,差不太多,不说了。