首页 > 其他 > 详细

properties使用

时间:2014-04-08 22:16:17      阅读:515      评论:0      收藏:0      [点我收藏+]

properties可以load store

注释可以采用 "#" 或者"!"

分隔采用"="或者":"

分行采用" \"

 

由于property类继承的是hashtable,可以采用put putall 但是不推荐

 

bubuko.com,布布扣
/**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        Properties props = new Properties();
        InputStream input = new FileInputStream(new File("D:/javaDevelop/oddjob-1.4.0-SNAPSHOT-src/oddjob-src/oddjob/src/target/classes/my.properties"));
        
        props.load(input);
        input.close();
        System.out.println(props.getProperty("aa"));
        System.out.println(props.getProperty("bb"));
        System.out.println(props.getProperty("cc"));
        OutputStream os =System.out;
        props.storeToXML(os, "fdasfsa");
        props.store(os, "putong");
        props.list(System.out);
    }
bubuko.com,布布扣

 

 

bubuko.com,布布扣
 1 package com.zuidaima;
 2 
 3 import java.io.File;
 4 import java.io.FileInputStream;
 5 import java.io.FileOutputStream;
 6 import java.io.IOException;
 7 import java.util.Properties;
 8 
 9 public class Main {
10 
11     public static void main(String[] args) {
12         Properties property = new Properties();
13         try {
14             File file = new File("c:/db.properties");
15             if (!file.exists()) {
16                 file.createNewFile();
17             }
18             // 写入
19             property.setProperty("database", "localhost");
20             property.setProperty("user", "zuidaima");
21             property.setProperty("password", "password");
22             property.store(new FileOutputStream(file), null);
23 
24             property.load(new FileInputStream(file));
25 
26             // 读取
27             System.out.println(property.getProperty("database"));
28             System.out.println(property.getProperty("user"));
29             System.out.println(property.getProperty("password"));
30         } catch (IOException e) {
31             e.printStackTrace();
32         }
33     }
34 }
35 
36                     
bubuko.com,布布扣

 

properties使用,布布扣,bubuko.com

properties使用

原文:http://www.cnblogs.com/blachie/p/3651402.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!