- import java.io.*;
- import java.util.*;
- class PropertiesDemo
- {
- public static void main(String[] args) throws IOException
- {
- getPro();
- }
- public static void getPro()
- {
- Properties pro=new Properties(); //创建一个Properties集合对象
- pro.setProperty("shengyi","21"); //添加一个键值对
-
- pro.setProperty("linyong","22");
- //Set<String> sets=pro.stringPropertyNames(); //返回键字符串的集合
- //for (String s:sets)
- //{
- // System.out.println(s+":"+pro.getProperty(s)); //获取键对应的值
- //}
-
- System.out.println(pro);
- }
- public static void funProperties()throws IOException
- {
- Properties pro=new Properties();
- BufferedReader br=new BufferedReader(new FileReader("F:\\properties.txt")); //与配置文件相关联
- String line=null;
- while ((line=br.readLine())!=null) //读取到每一行的键值对
- {
- String[] aa=line.split("="); //通过=切割字符串
-
- pro.setProperty(aa[0],aa[1]); //切割后的前面做键,后者做值
- }
- br.close();
-
- System.out.println(pro); //输出是倒过来输出的?
- }
- }
复制代码
你们是不是倒过来了,谁能解释一下为什么是倒过来的 |
|