????2????????????????????Test.properties??
????name=JJ
????Weight=4444
????Height=3333
????1 public class getProperties {
????2     public static void main(String[] args) throws FileNotFoundException?? IOException {
????3         Properties pps = new Properties();
????4         pps.load(new FileInputStream("Test.properties"));
????5         Enumeration enum1 = pps.propertyNames();//????????????????
????6         while(enum1.hasMoreElements()) {
????7             String strKey = (String) enum1.nextElement();
????8             String strValue = pps.getProperty(strKey);
????9             System.out.println(strKey + "=" + strValue);
????10         }
????11     }
????12 }
????3???????????????
????????key???value
???????properties????????
????д???μ?properties???
1 //????Properties????????
2 public class TestProperties {
3     //????Key???Value
4     public static String GetValueByKey(String filePath?? String key) {
5         Properties pps = new Properties();
6         try {
7             InputStream in = new BufferedInputStream (new FileInputStream(filePath));
8             pps.load(in);
9             String value = pps.getProperty(key);
10             System.out.println(key + " = " + value);
11             return value;
12
13         }catch (IOException e) {
14             e.printStackTrace();
15             return null;
16         }
17     }
18
19     //???Properties????????
20     public static void GetAllProperties(String filePath) throws IOException {
21         Properties pps = new Properties();
22         InputStream in = new BufferedInputStream(new FileInputStream(filePath));
23         pps.load(in);
24         Enumeration en = pps.propertyNames(); //????????????????
25
26         while(en.hasMoreElements()) {
27             String strKey = (String) en.nextElement();
28             String strValue = pps.getProperty(strKey);
29             System.out.println(strKey + "=" + strValue);
30         }
31
32     }
33
34     //д??Properties???
35     public static void WriteProperties (String filePath?? String pKey?? String pValue) throws IOException {
36         Properties pps = new Properties();
37
38         InputStream in = new FileInputStream(filePath);
39         //?????????ж???????б???????????
40         pps.load(in);
41         //???? Hashtable ????? put????? getProperty ?????????????
42         //????????????????????????????????? Hashtable ???? put ??????
43         OutputStream out = new FileOutputStream(filePath);
44         pps.setProperty(pKey?? pValue);
45         //???????? load ????????? Properties ???е?????
46         //???? Properties ???е??????б???????????д???????
47         pps.store(out?? "Update " + pKey + " name");
48     }
49
50     public static void main(String [] args) throws IOException{
51         //String value = GetValueByKey("Test.properties"?? "name");
52         //System.out.println(value);
53         //GetAllProperties("Test.properties");
54         WriteProperties("Test.properties"??"long"?? "212");
55     }
56 }
?????????
????Test.properties??????????????
????#Update long name
????#Sun Feb 23 18:17:16 CST 2014
????name=JJ
????Weight=4444
????long=212
????Height=3333