Properties的读取和写入

 1 public class ProperticesDemo {
 2     @Test
 3     public void test(){
 4         Properties pro = new Properties();
 5         try {
 6             pro.load(new FileInputStream("f:\\1.txt"));
 7         } catch (FileNotFoundException e) {
 8             e.printStackTrace();
 9         } catch (IOException e) {
10             e.printStackTrace();
11         }
12         Set<Entry<Object, Object>> s = pro.entrySet();
13         for(Entry<Object, Object> t:s){
14             System.out.println(t);
15             System.out.println(t.getKey());
16             System.out.println(t.getValue());
17 //            try {
18 //                String temp = (String) t.getValue();
19 //                System.out.println(new String(temp.getBytes("ISO8859_1"),"gbk"));
20 //            } catch (UnsupportedEncodingException e) {
21 //                e.printStackTrace();
22 //            }
23         }
24     }
25     @Test
26     public void test1(){
27         Properties pro = new Properties();
28         pro.setProperty("111", "哈哈");
29         try {
30             pro.store(new FileOutputStream("f:\\1.txt"), "");
31         } catch (FileNotFoundException e) {
32             e.printStackTrace();
33         } catch (IOException e) {
34             e.printStackTrace();
35         }
36     }
37 }


 

posted @ 2014-05-10 21:04  一路向北中  阅读(215)  评论(0)    收藏  举报