`
yupeng_raul7
  • 浏览: 1609 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
社区版块
存档分类
最新评论

configuration file

阅读更多

自我练习

dependence jar file
commons-configuration-1.6\commons-configuration-1.6.jar;
commons-lang-2.4.jar;
commons-logging-1.1.1\commons-logging-1.1.1.jar;
commons-collections-3.2.1\commons-collections-3.2.1.jar


import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.apache.commons.configuration.PropertiesConfiguration;

public class ScheduleConfig {

public static void main(String[] args) throws Exception {

/**
* load by name
*/
PropertiesConfiguration cfg = new PropertiesConfiguration(
"schdule.properties");
String name = cfg.getString("raul");
System.out.println("----------" + name);
Iterator it = null;
it = cfg.getKeys();
while (it.hasNext()) {
// System.out.println(cfg.getString(it.next().toString()));
System.out.println(it.next());
}

String[] str = cfg.getStringArray("raul");
List list = cfg.getList("raul");

for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
System.out.println(list.get(i));
}

cfg.clear();
// cfg.load(new File("/names.properties"));

// System.out.println(str);

// // String path = new File("schedule.properties").getPath();
/**
* load by file
*/
File file = new File("bin/names.properties");
String path = file.getAbsolutePath();
System.out.println(path+"--------properties after clear ");
cfg.setFile(file);
cfg.load(file);
it = cfg.getKeys();
while (it.hasNext()) {
System.out.println(it.next());
}

// file.delete(); //this method is delete a file from disk
file = new File("bin/jdbc.properties");
InputStreamReader isr = new InputStreamReader(new FileInputStream(file));
System.out.println("user file stream:--->" + file.getName()
+ file.getAbsolutePath() + ">>>>>");
cfg.getInclude(); ///this method make two config file into a file;
cfg.clear();//if you not use properties any more clear it.
cfg.load(isr);
while (isr.read() != -1) {
System.out.println((char) isr.read());
}
it = cfg.getKeys();
while (it.hasNext()) {
System.out.println(it.next());
}

// print system properties
Properties p = System.getProperties();
// p.list(System.out);
System.out.println("______:" + System.getProperty("java.class.path"));



}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics