Properties中的load方法主要是建立Properties与输出流之间的关联。
原a.txt中的内容为:
代码:
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Properties;
public class Demo2 {
public static void main(String[] args) throws Exception {
Properties prop=new Properties();
//一行一行的读
BufferedReader bfr=new BufferedReader(new FileReader("a.txt"));
String line=null;
while((line=bfr.readLine())!=null){
if(line.startsWith("#")){//以'#'开头的不要
continue;
}
String[] strs=line.split("=");//以'='作为分割
prop.setProperty(strs[0], strs[1]);
}
prop.list(System.out);//将结果显示在控制台上
}
}
输出结果为: