模拟load()方法将指定流中的属性列表加载到properties中

public class TestDriver {


	public static void main(String[] args) throws IOException {
		File file = new File("e:\\test.config");
		//模拟load()方法将指定流中的属性列表加载到properties中,指定文件必须是键值对形式
		Properties ps = new Properties();
		BufferedReader bufR = new BufferedReader(new FileReader(file));
		String bufStr = null;
		while((bufStr = bufR.readLine()) != null){
			if(bufStr.startsWith("#")){
				continue;
			}
			String[] strs = bufStr.split("=");
			ps.setProperty(strs[0], strs[1]);
		}
		System.out.println("=================");
		ps.list(System.out);
	}
}

  这就相当于

public class TestDriver {


	public static void main(String[] args) throws IOException {
		File file = new File("e:\\test.config");
		//load()方法将指定流中的属性列表加载到properties中,指定文件必须是键值对形式
		Properties ps = new Properties();
		System.out.println("=================");
		ps.load(new FileReader(file));
                ps.list(System.out);
	}
}

  

posted @ 2014-03-09 21:11  lxricecream  阅读(292)  评论(0)    收藏  举报