- import java.util.*;
- import java.io.*;
- class PropertiesDemo
- {
- public static void main(String[] args) throws Exception
- {
- //set();
- try
- {
- Properties ps=new Properties();
- get("e:\\P.txt",ps);
- set(ps);
- }
- catch (Exception e)
- {
- e.toString();
- }
- }
- public static void get(String files,Properties pro) throws Exception
- {
- BufferedReader br=new BufferedReader(new FileReader(files));
- String line=null;
- while((line=br.readLine())!=null)
- {
- String []arr=line.split("=");
- pro.setProperty(arr[0],arr[1]);
- }
- }
- public static void set(Properties pro)
- {
- Set<String>list=pro.stringPropertyNames();//将Properties中数据遍历返回Set集合
- for(String p:list)
- {
- System.out.println(p+" "+pro.getProperty(p));
- }
-
- }
-
- }
复制代码 从get()方法中的while循环出来就没有结果
|
|